Propeller Manual

Table Of Contents
2: Spin Language Reference – STRCOMP
STRCOMP
Command: Compare two strings for equality.
((PUB PRI))
STRCOMP (StringAddress1, StringAddress2 )
Returns: TRUE if both strings are equal, FALSE otherwise.
StringAddress1 is an expression specifying the starting address of the first string to
compare.
StringAddress2 is an expression specifying the starting address of the second string to
compare.
Explanation
STRCOMP is one of two commands (STRCOMP and STRSIZE) that retrieve information about a
string.
STRCOMP compares the contents of the string at StringAddress1 to the contents of the
string at StringAddress2, up to the zero-terminator of each string, and returns
TRUE if both
strings are equivalent,
FALSE otherwise. This comparison is case-sensitive.
Using STRCOMP
The following example assumes
PrintStr is a method created elsewhere.
PUB Main
if strcomp(@Str1, @Str2)
PrintStr(string("Str1 and Str2 are equal"))
else
PrintStr(string("Str1 and Str2 are different"))
DAT
Str1 byte "Hello World", 0
Str2 byte "Testing.", 0
The above example has two zero-terminated strings in the DAT block, Str1 and Str2. The
Main method calls
STRCOMP to compare the contents of each string. Assuming PrintStr is a
method that displays a string, this example prints “Str1 and Str2 are different” on the display.
Propeller Manual v1.1 · Page 203