Go to the first, previous, next, last section, table of contents.


Comparison of Characters and Strings

Function: char-equal character1 character2
This function returns t if the arguments represent the same character, nil otherwise. This function ignores differences in case if case-fold-search is non-nil.

(char-equal ?x ?x)
     => t
(char-to-string (+ 256 ?x))
     => "x"
(char-equal ?x  (+ 256 ?x))
     => t

Function: string= string1 string2
This function returns t if the characters of the two strings match exactly; case is significant.

(string= "abc" "abc")
     => t
(string= "abc" "ABC")
     => nil
(string= "ab" "ABC")
     => nil

The function string= ignores the text properties of the two strings. To compare strings in a way that compares their text properties also, use equal (see section Equality Predicates).

Function: string-equal string1 string2
string-equal is another name for string=.

Function: string< string1 string2
This function compares two strings a character at a time. First it scans both the strings at once to find the first pair of corresponding characters that do not match. If the lesser character of those two is the character from string1, then string1 is less, and this function returns t. If the lesser character is the one from string2, then string1 is greater, and this function returns nil. If the two strings match entirely, the value is nil.

Pairs of characters are compared by their ASCII codes. Keep in mind that lower case letters have higher numeric values in the ASCII character set than their upper case counterparts; numbers and many punctuation characters have a lower numeric value than upper case letters.

(string< "abc" "abd")
     => t
(string< "abd" "abc")
     => nil
(string< "123" "abc")
     => t

When the strings have different lengths, and they match up to the length of string1, then the result is t. If they match up to the length of string2, the result is nil. A string of no characters is less than any other string.

(string< "" "abc")
     => t
(string< "ab" "abc")
     => t
(string< "abc" "")
     => nil
(string< "abc" "ab")
     => nil
(string< "" "")
     => nil                   

Function: string-lessp string1 string2
string-lessp is another name for string<.

See also compare-buffer-substrings in section Comparing Text, for a way to compare text in buffers. The function string-match, which matches a regular expression against a string, can be used for a kind of string comparison; see section Regular Expression Searching.


Go to the first, previous, next, last section, table of contents.