String Compare
From Erlang Community
(Difference between revisions)
| Revision as of 21:56, 18 August 2006 (edit) Cyberlync (Talk | contribs) ← Previous diff |
Current revision (21:52, 3 September 2006) (edit) (undo) Bfulgham (Talk | contribs) |
||
| Line 35: | Line 35: | ||
| </code> | </code> | ||
| - | [[Category:CookBook]] | + | [[Category:CookBook]][[Category:StringRecipes]] |
Current revision
[edit] Problem
You need to compare two strings.
[edit] Solution
Use the comparison functions from the string library for equality:
1> string:equal("ABC", "abc").
false
2> string:equal("abc", "abc").
true
|
You can use the normal equality operators for sorting and other types of comparisons:
3> G = "ABC". "ABC" 4> L = "abc". "abc" 5> G > L. false 6> G < L. true 7> G >= L. false 8> G =< L. true |
Note that lower case characters are considered greater than uppercase in these orderings.
Note that case insensitive versions of these functions are not available, though you can always use the httpd_util library to_lower or to_upper functions to put the two strings on an equal footing:
9> string:equal(httpd_util:to_lower("AAA"), "aaa").
true
|

Digg It
Del.icio.us
Reddit
Facebook
Stumble Upon
Technorati

