Erlang Central

Difference between revisions of "String Convert To From ASCII"

From ErlangCentral Wiki

m
m (Reverted edits by Kaiserpanda (Talk); changed back to last version by Bfulgham)
Line 34: Line 34:
  
 
[[Category:CookBook]][[Category:StringRecipes]]
 
[[Category:CookBook]][[Category:StringRecipes]]
 
 
 
[http://www.gambling-online-theory.com/online-casino/online-casino-for-cash.html online casino for cash]
 
[http://www.casino-web-gambling.com/blackjack-tips/blackjack-hints.html blackjack hints]
 
[http://www.gambling-online-theory.com/casinos-portal/free-casinos-on-line.html free casinos on line]
 
[http://www.casinos-new.com/internet-casino.html Online casino - Internet Casinos]
 
[http://www.3wcasinos.com/roulette-tips/roulette-description.html roulette description]
 
[http://www.magical-casino.com/casino_risk.html Gambling Online - Risks.]
 
[http://www.magical-casino.com/no_deposit.html Casinos with no deposit required.]
 
[http://www.casino-theory.com/online-casino-royale/online-casino-gamble.html online casino gamble]
 
[http://www.casino-theory.com/online-casino-bonus/online-casino-net.html online casino net]
 
[http://www.slots-wiki.com/index.php/slots_online_bonus slots online bonus]
 

Revision as of 08:50, 4 December 2006

Problem

You want to get the number representing the ASCII value of a character, or you want to display the characters associated with a particular ASCII numerical value.


Solution

All ASCII character values are identical to integers, and strings of characters are identical to lists of integers. Consequently, in most cases character values are already in the format you wish:

1> $C.
67
2> H = $C.
67
3> H.
67

Because integer values are the only character representations (and the $C notation is just a syntactic convenience), values that map to ASCII (or UNICODE) values may be used where characters are desired:

1> io:format("Number ~w is character ~c\n", [101, 101]).
Number 101 is character e
ok
2> io:format("~w~n", ["Sample"]).
[83,97,109,112,108,101]
ok
3> io:format("~s~n", [[83, 97, 109, 112, 108, 101]]).
Sample
ok
4> io:format("~s~n", [lists:map(fun(C) -> C+1 end, "HAL")]).
IBM
ok