e r l a n g : c o o k b o o k

/ Erlang.StringCompare

This Web


WebHome 
WebChanges 
TOC
NewRecipe 
WebTopicList 
WebStatistics 

All Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Erlang Links


Erlang.org
Erlang Wiki
ErlMan
Erlang Wiki
The Jungerl
Erlang-fr.org
Joe Armstrong
Lambda the Ultimate

Erlang Web Ring


[Prev]: Joe Armstrong's Page
[Next]: Joe Armstrong's Page

Comparing Strings

Problem

You need to compare two strings.

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

Discussion

TODO: talk about case sensitivity when you're working with text that's not English.

Contributors

Based on work by GordonWeakliem and NoelWelsh.

-- BrentAFulgham - 21 Aug 2004

CookbookForm
TopicType: Recipe
ParentTopic: StringRecipes
TopicOrder: 160

 
 
Copyright © 2004 by the contributing authors. All material on the Erlang Cookbook web site is the property of the contributing authors.
This material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest