Strcmp

From SA-MP

Jump to: navigation, search


strcmp

strcmp can be used to compare whetever two strings are the same, but has (as all functions), problems with cyrillic characters. Another problem of this function is, if one string of both is empty, strcmp will return 0 (same when strings are the same).


(const string1[], const string2[], bool:ignorecase, length)
string1The first string to compare.
string2The second string to compare.
ignorecase (optional)When set to true, the case doesn't matter - HeLLo is the same as Hello. When false, they're not the same.
length (optional)When this length is set, the first x chars will be compared - doing "Hello" and "Hell No" with a length of 4 will say it's the same string.
Returns0 if the strings are the same.


Good examples of using strcmp can be found at the Using strcmp()-Tutorial.


Note:

(for problems on comparing strings from a textfile)

It is recomment to use strlen(one of your strings) for the lentgh param. If you don't and compare one string from a textfile with an other variable strcmp will not return 0 (only if length is larger then the string in the file).

This is because the string in the file got the \r\n for the line return on its end.

So if you use strcmp to compare textfile strings do that like this:

strcmp(stringfromvariable,stringfromatextfile,true or false, getlength(stringfromvariable))

so the \r\n in your file will be ignored because it is out out the range to compare!


Related Functions

The following functions might be useful as well, as they're related to this function in one way or another.

Personal tools