[erlang-questions] how to escape ? character
Mazen Harake
mazen.harake@REDACTED
Sat May 15 12:47:59 CEST 2010
One can also use the notation $<chr> which is slightly more comfortable
when it comes to individual chars.
Try e.g this in the shell:
1> $?.
63
Note however that this is not an Erlang string!
$? is not a string, [$?] however is.
/M
On 15/05/2010 00:52, Jeroen Koops wrote:
> 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
>>
>>
>
---------------------------------------------------
---------------------------------------------------
WE'VE CHANGED NAMES!
Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.
www.erlang-solutions.com
More information about the erlang-questions
mailing list