Erlang Central

Difference between revisions of "String Filter For Character Set"

From ErlangCentral Wiki

Line 17: Line 17:
[ Online Casino - Choosing the best casinos.]
[ slots tips]
[ Casinos with no deposit required.]
[ free online casino tournament]
[ roulette description]
[ online casino games]
[ slots online]
[ Online casino strategies.]
[ gambling online bingo]
[ online casino tips]

Revision as of 08:03, 22 November 2006


You want to remove all but a specified set of characters from a string.


This is really a extension of what we talked about in StringCheckForChar. The Erlang lists module provides several functions that allow manipulations of strings (since they are simply lists of characters). For example, to remove non-letters from a string, we could define a predicate that recognizes only letters:

1> lists:filter(fun(X) -> lists:member(X, 
1>     "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") end,
1>     "Hello, World!").
37> lists:filter(fun(X) -> not lists:member(X,
37> "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") end,
37> "Hello, World!").
", !"