Jump to content

difference for !strcmp and strcmp?


Johxz

Recommended Posts

In the tutorial doc use this example !strcmp I was thinking that is Logical NOT, but isn't. Someone can explain this to me?

 

if(!strcmp(%userName, "Heather"))
      echo("User Found: " @ %userName);
   else if(%userName $= "Mich")
      echo("User Found: " @ %userName);
   else 
      echo("User " @ %userName @ " not found");

 

From the Tscript reference use this example. What is the difference?

if( strcmp( %var, "foobar" ) == 0 )
   echo( "%var is equal to 'foobar'" );
Link to comment
Share on other sites

Is this correct?

 

// Testing 1
function matchNum1(%numBer)
{
   if(strcmp(%numBer, "0"))
      echo("Number 0 Found.");
   else if(strcmp(%numBer, "1"))
      echo("Number 1 Found.");
   else 
      echo("Number " @ %numBer @ " not found");
}

 

Output:

matchNum1(0);
Number 1 Found 
matchNum1(1);
Number 0 Found

 

// Testing 2
function matchNum2(%numBer)
{
   if(!strcmp(%numBer, "0"))
      echo("Number 0 Found.");
   else if(!strcmp(%numBer, "1"))
      echo("Number 1 Found.");
   else 
      echo("Number " @ %numBer @ " not found");
}

 

Output:

matchNum2(0);
Number 0 Found 
matchNum1(1);
Number 1 Found
Link to comment
Share on other sites

Hey, people gotta learn what strcmp is/does at some point in time. It's no biggie.


Also, in TS, there's a string comparitor operator

 

if(%myString $= "ThingIWantToCheck") 
  return "woo";
if(%myString !$= "ThingIWantToCheck") 
  return "boo";

 

If you know you're dealing with strings, it can be a bit easier to just use that instead of using the strcmp function.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...