strcmp()strcmp()

比较两个字符串。Compares two strings.

此函数从比较每个字符串的第一个字符开始。The function starts comparing the first character of each string. 如果第一个字符相同,则继续比较接下来的字符对,直到字符不同或到达较短字符串的末尾。If they are equal to each other, it continues with the following pairs until the characters differ or until the end of shorter string is reached.

语法Syntax

strcmp(string1, string2)strcmp(string1, string2)

参数Arguments

  • string1:要比较的第一个输入字符串。string1 : first input string for comparison.
  • string2:要比较的第二个输入字符串。string2 : second input string for comparison.

返回Returns

返回一个整数值,指示字符串之间的关系:Returns an integral value indicating the relationship between the strings:

  • <0 - 第一个不匹配的字符在 string1 中的值小于 string2 中的值<0 - the first character that does not match has a lower value in string1 than in string2
  • 0 - 两个字符串的内容相同0 - the contents of both strings are equal
  • >0 - 第一个不匹配的字符在 string1 中的值大于 string2 中的值>0 - the first character that does not match has a greater value in string1 than in string2

示例Examples

datatable(string1:string, string2:string)
["ABC","ABC",
"abc","ABC",
"ABC","abc",
"abcde","abc"]
| extend result = strcmp(string1,string2)
string1string1 string2string2 resultresult
ABCABC ABCABC 00
abcabc ABCABC 11
ABCABC abcabc -1-1
abcdeabcde abcabc 11