Strcmp

From SA-MP Wiki

Jump to: navigation, search


Compares two strings to see if they are the same.


Parameters:
(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.


Returns-1 if string1 comes before string2
1 if string1 comes after string2
0 if the strings are the same (for the matched length).


Image:32px-Circle-style-warning.png Important Note: This function also returns 0 if either string is empty.


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


NOTE:

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 has \r\n for the line return at the end, so if you use strcmp to compare textfile strings do it like this:

strcmp(stringfromvariable, stringfromtextfile, true/false, strlen(stringfromvariable))

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


Related Functions

The following functions may be useful, as they are related to this function in one way or another.

  • Strfind: Search for a string in a string.
  • Strtok: Get the next word/parameter in a string.
  • Strdel: Delete part of a string.
  • Strins: Insert text into a string.
  • Strlen: Get the length of the string.
  • Strmid: Extract part of a string into another string.
  • Strpack: Pack a string into a destination.
  • Strval: Convert a string into an integer.
  • Strcat: Concatenate two strings into a destination reference.


External Links

http://www.compuphase.com/pawn/String_Manipulation.pdf

Personal tools
In other languages