Warning

You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.

This is an old revision of the document!


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 unmatching 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!