StrCmp

From ZDoom Wiki
Jump to: navigation, search


int StrCmp (str string1, str string2[, int maxcomparenum]);
int StrIcmp (str string1, str string2[, int maxcomparenum]);

Usage

Compares the two strings passed in arguments string1 and string2 character by character. If maxcomparenum is specified, it only compares up to maxcomparenum characters of each string.

StrIcmp is a case-insensitive version of StrCmp.

Parameters

  • string1: The string to compare string2 with.
  • string2: The string to compare string1 with.
  • maxcomparenum: The maximum number of characters of each string to compare.

Return Value

0 if the two strings or a portion of each string up to the maxcomparenum-th character are equal
a positive value if the first character that does not match has a greater value in string1
a negative value if the first character that does not match has a greater value in string2

Example

These examples are illustrative, you will need to put the function into right context and you will want to process the return value.

str s1 = "BFGBall";
str s2 = "BFGExtra";

StrCmp(s1, "BFGBall"); //returns 0
StrCmp(s1, s2); //returns a positive value
StrCmp(s2, s1); //returns a negative value
StrCmp(s1, s2, 3); //returns 0
StrCmp(s1, "bfgball"); //returns a positive value
StrICmp(s1, "bfgball"); //returns 0