[erlang-questions] String and single quote escaping

Sean Cribbs sean@REDACTED
Wed Oct 8 17:02:49 CEST 2014


Your last one is nearly correct. Try this:

3> io:format("~s~n", [re:replace("single quote ' etc...", "'",
"\\\\&", [{return, list}])]).
single quote \' etc...

Note that I used io:format so you don't get Erlang's term
representation but the literal string output.

On Wed, Oct 8, 2014 at 8:54 AM, Raffaele Intorcia
<raffaele.intorcia@REDACTED> wrote:
> Hi all, i’m getting crazy with string and quote escaping.
>
> I have a string like this:
>
>
>
> single quote ' etc...
>
>
>
> Now, i have to create a string that will be passed as query to a sqlserver
> so i need to escape the single quote. To do this i’m using re:replace for
> example with these syntax :
>
>
>
> 2> re:replace("single quote ' etc...", "'", "\'", [{return, list}]).
>
> "single quote ' etc..."
>
>
>
> 2> re:replace("single quote ' etc...", "'", "\\'", [{return, list}]).
>
> "single quote ' etc..."
>
>
>
> 2> re:replace("single quote ' etc...", "'", "\\\'", [{return, list}]).
>
> "single quote ' etc..."
>
>
>
> 2> re:replace("single quote ' etc...", "'", "\\\'", [{return, list}]).
>
> "single quote \\' etc..."
>
>
>
> All of these results is not what i want. I’m looking for this:
>
>
>
> "message with single quote \' etc..."
>
>
>
> Anyone knows how i can achieve this?
>
>
>
> Thank you!!
>
>
>
> Bye
>
> Raf
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>



-- 
Sean Cribbs <sean@REDACTED>
Sr. Software Engineer
Basho Technologies, Inc.
http://basho.com/



More information about the erlang-questions mailing list