next up previous

12.3.9 Comparing Two Strings

The str-compare function will compare two strings to determine their logical relationship (i.e., equal to, less than, greater than). The comparison is performed character-by-character until the strings are exhausted (implying equal strings) or unequal characters are found. The positions of the unequal characters within the ASCII character set are used to determine the logical relationship of unequal strings.

Syntax

(str-compare <string-or-symbol-expression>
             <string-or-symbol-expression>)

This function returns an integer representing the result of the comparison (0 if the strings are equal, < 0 if the first argument < the second argument, and > 0 if the first argument > the second argument).

Example

CLIPS> (< (str-compare "string1" "string2") 0)
TRUE   ; since "1" < "2" in ASCII character set
CLIPS> (str-compare "abcd" "abcd")
0
CLIPS>


next up previous