[erlang-questions] Stripping slashes from a string
Wes James
comptekki@REDACTED
Fri Apr 27 17:24:22 CEST 2012
On Thu, Apr 26, 2012 at 11:17 PM, Martin Dimitrov
<mrtndimitrov@REDACTED> wrote:
> Hello,
>
> I have a string as the following:
>
> "This is some\\r\\ntext"
>
> I am trying to replace "\\r" with \r and "\\n" with \n.
>
> I do it with the following two reg expressions:
>
> R1 = re:replace(Result, "\\\\r", "\\\r", [{return,list}, global, unicode]),
> R2 = re:replace(R1, "\\\\n", "\\\n", [{return,list}, global, unicode]),
>
> Is there a better way? I tried to combine the two regex like:
not sure if better...
but just some other ways to do it :)
1> A="This is some\\r\\ntext".
"This is some\\r\\ntext"
2> re:replace(A,"\\\\r\\\\n","\r\n",[{return,list}, global, unicode]).
"This is some\r\ntext"
or
1> A = "This is some\\r\\ntext".
"This is some\\r\\ntext"
2> [C,D] = string:tokens(A,"\\r\\n").
["This is some","text"]
3> C ++ "\r\n" ++ D.
"This is some\r\ntext"
-wes
More information about the erlang-questions
mailing list