Use strcmp to compare 2 strings
#4

Hi there,

The use of strcmp (string compare) is easy. But, it can be a little bit tricky for beginners. There is 4 parameters in the function:
  • String number 1
  • String number 2
  • Case sensitivity (boolean) (NOT REQUIRED, will give false if not specified)
  • Length (NOT REQUIRED)
You may use it like that:
pawn Code:
String1 = "Hello";
  String2 = "hello";
  printf("%d", strcmp(String1, String2, false)); // will print "-1" as it is case sensitive because of the third parameter which is false.
  printf("%d", strcmp(String1, String2, true)); // will print "0" as the strings are matching.
That is how you use strcmp. Strcmp is also used for creating commands such as /kill, here is an example:
pawn Code:
if(strcmp(cmdtext, "/kill", true) == 0) // You may also use "!strcmp(cmdtext, "/kill", true))".
  {
    SetPlayerHealth(playerid, 0.0);
    return 1;
  }
Have fun scripting.

Kind regards,

Francis Morissette
SA-MP Scripter
http://sa-mp.com
Reply


Messages In This Thread
Use strcmp to compare 2 strings - by TimBuk.Ekh - 18.04.2009, 20:16
Re: Use strcmp to compare 2 strings - by yom - 18.04.2009, 20:39
Re: Use strcmp to compare 2 strings - by TimBuk.Ekh - 18.04.2009, 20:42
Re: Use strcmp to compare 2 strings - by Francis[French] - 18.04.2009, 21:38
Re: Use strcmp to compare 2 strings - by TimBuk.Ekh - 18.04.2009, 21:42
Re: Use strcmp to compare 2 strings - by Francis[French] - 18.04.2009, 21:44
Re: Use strcmp to compare 2 strings - by Stakline - 21.06.2010, 21:31
Re: Use strcmp to compare 2 strings - by Joe_ - 21.06.2010, 21:34

Forum Jump:


Users browsing this thread: 1 Guest(s)