Elisp: String Comparison, Equality, Order
Equality Test
string-equal
-
For comparing
- Two Strings
- Two Symbols
- A string and a symbol
;; dedicated function for comparing string (string-equal "abc" "abc") ; t ;; string case matters (string-equal "abc" "Abc") ; nil ;; can be used to compare two symbols (string-equal 'abc 'abc) ; t ;; can be used to compare string and symbol (string-equal "abc" 'abc) ; t
string-equal-ignore-case
-
like
string-equal
but Case-Insensitive.new in Emacs 29 (Released 2023-07)
compare-strings
-
(compare-strings STR1 START1 END1 STR2 START2 END2 &optional IGNORE-CASE)
test substring equality, and optionally ignore case.
(compare-strings "xx3" 0 2 "xx4" 0 2) ;; t
string-collate-equalp
-
(string-collate-equalp S1 S2 &optional LOCALE IGNORE-CASE)
test string equality but consider similar character as equivalent. e.g. the unicode ligature char fi is considered equal to character sequence
fi
.(string-collate-equalp "fi" "fi") ;; t ;; fi ;; name: LATIN SMALL LIGATURE FI ;; codepoint 64257
String Comparison
string-greaterp
string-collate-lessp
string-version-lessp
string-prefix-p
string-suffix-p
string-distance