[erlang-questions] Conversion of string into Ascii values ??

Richard Carlsson richardc@REDACTED
Thu Feb 28 12:46:00 CET 2008


J Bhanot wrote:
> In following code:
> 
> add(Mymsg) ->
>  io:format("jbss msg  ~w~n", [Mymsg]),
> 
> when I am executing complex3:add(["abc"]).......where complex3 is my 
> module name.....
> 
> I get the output as
> 
> jbss msg  [97,98,99]........
> 
> Why is it coverting abc in ascii value.....

Because ~w prints the term representation as it is.
If you use ~p, it's almost the same, but pretty-printed,
so a string (a list of printable character codes) will be
printed within double quotes.

> Is there a way in which I can get -
> 
> jbss msg abc

To print just the characters in a string (or atom),
without any surrounding quotes, use ~s, as in:

   io:format("jbss msg  ~s~n", [Mymsg])

     /Richard





More information about the erlang-questions mailing list