[erlang-questions] Strings as Lists
Christian S
chsu79@REDACTED
Fri Feb 15 10:58:21 CET 2008
2008/2/15 Dmitrii 'Mamut' Dimandt <dmitriid@REDACTED>:
> This is only true for ASCII text ;) Non-ASCII gets screwed up badly:
>
> lists:reverse("text") %% gives you "txet"
> lists:reverse("текст") %% Russian for text becomes
> [130,209,129,209,186,208,181,208,130,209] which is clearly not what I wanted
> :)
This is what you should have in your list:
1> Text = [16#442, 16#435, 16#43a, 16#441, 16#442].
[1090,1077,1082,1089,1090]
You can convert it to utf8 for output
2> xmerl_ucs:to_utf8(Text).
[209,130,208,181,208,186,209,129,209,130]
And you can reverse it and convert that to utf8.
3> xmerl_ucs:to_utf8(lists:reverse(Text)).
[209,130,209,129,208,186,208,181,209,130]
More information about the erlang-questions
mailing list