[erlang-questions] how to escape ? character

Jeroen Koops koops.j@REDACTED
Fri May 14 23:52:11 CEST 2010


Hi Wes,

In Erlang, a string is simply a list of integers that are all valid ASCII
values. The expressions "hello" and [ 104, 101, 108, 108, 111 ] are exactly
the same.
The shell (and some of the the format modifiers in io:format) has some
intelligence - if it has to print a list that seems to consist mostly of
ASCII values, it will display it as a double-quoted string - otherwise, it
will display it as a list-in-square-brackets.

As such, there's no need for ord and char functions in Erlang. If you want
to print the value of say ASCII character 42, simply do something like
this:io:format("~s", [ [42] ]).
If you want to print the ASCII values of all characters in the string
"hello", simply do something like this: lists:foreach(fun(C) ->
io:format("~b~n", [C]) end, "hello").

On Fri, May 14, 2010 at 11:36 PM, Wes James <comptekki@REDACTED> wrote:

> On Fri, May 14, 2010 at 3:32 PM, Jeroen Koops <koops.j@REDACTED> wrote:
> > "How do I escape " ++ [63] ++ " in a string" ++ [63].
> >
> > On Fri, May 14, 2010 at 11:25 PM, Wes James <comptekki@REDACTED> wrote:
> >>
> >> How do I escape ? in a string.  The runtime things it is an illegal
> >> macro call.  Even if I do \?.
> >>
>
>
> Jeroen,
>
> Thx.  As I was looking on erlang.org in the docs for this - I was also
> looking for ord and char like functions.  What are they called and
> under what module?  I'm looking in the stdlib, but can't see them
> anywhere.  i.e. ord("m") -> integer value and char(integer value) ->
> some letter.
>
> thx,
>
> -wes
>


More information about the erlang-questions mailing list