STRCMP()

Syntax:

strcmp(<string pointer arg1>, <string pointer arg2>)

The STRCMP() function is used to compare two strings. It compares the strings that the arguments point to, character by character. The comparison stops at the first unmatched character, or if one of the strings end. The function returns an integer as the result of the comparison:

Return valueMeaning
0Strings are identical (equal).
negative integer The PETSCII value of first unmatched character is less than second.
positive integerThe PETSCII value of first unmatched character is greater than second.

Example:

a$ = "hello"
b$ = "hello"
print strcmp(a$, b$)
rem -- the above outputs: 0
b$ = "hello world"
print strcmp(a$, b$)
rem -- the above outputs: -32
print strcmp("john taylor", "john smith")
rem -- the above outputs: 1

Note: Do not use the = operator to compare strings! It will only return true if two string pointers point to the same address!

Discussion

Enter your comment. Wiki syntax is allowed:
D M L P​ N
 
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies