String Convert To From ASCII
From Erlang Community
(Difference between revisions)
| Revision as of 21:29, 18 August 2006 (edit) Cyberlync (Talk | contribs) ← Previous diff |
Revision as of 21:50, 3 September 2006 (edit) (undo) Bfulgham (Talk | contribs) Next diff → |
||
| Line 33: | Line 33: | ||
| - | [[Category:CookBook]] | + | [[Category:CookBook]][[Category:StringRecipes]] |
Revision as of 21:50, 3 September 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
|

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

