[erlang-questions] Re: How to remove \ from string

Richard O'Keefe ok@REDACTED
Thu Apr 7 03:08:33 CEST 2011


On 7/04/2011, at 5:36 AM, Muhammad Yousaf wrote:

> 
> Thanks a lot but i only want to remove backslash not double quotes 
> for example
> 
> Val = <<"{get,\"user\",\"wilson\",\"lname\"}">> ,

The backslashes are in the printout but not in the data.

1> length(binary_to_list(<<"a\"b\"c">>)).
5
2> [A,B,C,D,E] = binary_to_list(<<"a\"b\"c">>).
"a\"b\"c"
3> {A,B,C,D,E}.
{97,34,98,34,99}

(Backslash is ASCII 92.  You see none of them here.)

> 
> i need Val= <<"{get,"user","wilson","lname"}">>

That's what you *have*; the backslashes are there in the display
(or the input) so that you don't mistake the data quotes for
terminator quotes.

> 
> what i am doing with your help 
> 
> re:replace(Val,["\\"],"",[global, {return,list}]). getting error
> [X||X<-"{get,\"user\",\"wilson\",\"lname\"}",X=/=$\\].

Try this.
4> [X || X <- "{get,\"user\",\"wilson\",\"lname\"}", X =:= $\\].
[]

The answer is an empty list because there aren't any backslash
character codes in the string to start with.





More information about the erlang-questions mailing list