Difference between revisions of "String Convert To From ASCII"
From ErlangCentral Wiki
|(One intermediate revision by one user not shown)|
Revision as of 08:50, 4 December 2006
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.
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