String Case
From Erlang Community
(Difference between revisions)
| Revision as of 03:34, 23 November 2006 (edit) Kaiserpanda (Talk | contribs) m ← Previous diff |
Current revision (09:47, 23 November 2006) (edit) (undo) 213.171.204.166 (Talk) (→Solution) |
||
| Line 24: | Line 24: | ||
| [[Category:CookBook]][[Category:StringRecipes]] | [[Category:CookBook]][[Category:StringRecipes]] | ||
| - | |||
| - | |||
| - | |||
| - | [http://www.casino-games-wiki.com/index.php/online_casino_games online casino games] | ||
| - | [http://www.casinos-new.com/blackjack.html Online casino - Blackjack online] | ||
| - | [http://www.casino-theory.com/bingo-online/gambling-online-bingo.html gambling online bingo] | ||
| - | [http://www.casino-theory.com/online-casino-royale/online-casino-gamble.html online casino gamble] | ||
| - | [http://www.casinos-new.com/poker.html Online casino - Poker in casino] | ||
| - | [http://www.casino-theory.com/craps-rules/internet-craps-gambling.html internet craps gambling] | ||
| - | [http://www.magical-casino.com/online_games.html Online casino games.] | ||
| - | [http://www.casino-games-wiki.com/index.php/casino_games_rules casino games rules] | ||
| - | [http://www.3wcasinos.com/roulette-tips/roulette-description.html roulette description] | ||
| - | [http://www.slots-wiki.com/index.php/online_slots online slots] | ||
Current revision
[edit] Problem
You need to convert a string to all uppercase or all lowercase.
[edit] Solution
For ASCII, you can do it yourself in this simple manner:
to_upper(S) -> lists:map(fun char_to_upper/1, S). to_lower(S) -> lists:map(fun char_to_lower/1, S). char_to_upper(C) when C >= $a, C =< $z -> C bxor $\s; char_to_upper(C) -> C. char_to_lower(C) when C >= $A, C =< $Z -> C bxor $\s; char_to_lower(C) -> C. |
For many other languages where case-change makes sense, you can extend the above in a simple manner by adding new ranges or specific characters to the char_to_*/1 functions. For some, you may need extra processing in to_upper/1 or to_lower/1.
Erlang doesn't have a nice unicode-respectful way of doing this. If you'd like to prototype such a way, you might start with:
-module(unicode).
-record(unicode_string,{encoding,language,data}).
|

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

