[erlang-questions] string conversion

info <>
Fri Jun 19 20:00:27 CEST 2009


I don't know if we can indicate several options ...
I must try.

This time sending to the list too...

2009/6/19, info  < >:
> Hi All,
> How to simplify the P1-P2-P3 sequence:
>
> {ok, Bin} = file:read_file("example.xml"),        % read a binary string
> P1 = re:replace(Bin,"\\s","",[global]),               % remove all
> whitespaces
> P2 = list_to_binary(P1),                                 % convert [list] in
> binary
> P3 = binary_to_list(P2),                                 % convert binary to
> list
>
> I = str(P3,"string_to_find"),                             % str(list,list)
>
> str(P1,"string_to_find") hangs. That is why I used this trick but it is not
> a good code ...

Haven't tried, but

P1 = re:replace(Bin,"\\s","",[global, {return list}]),

doesn't help? By the way, it might be useful to set the return type
globally for the re application...

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org


More information about the erlang-questions mailing list