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

David Mercer dmercer@REDACTED
Thu Apr 7 16:42:45 CEST 2011


Input: You have a binary with the text of an Erlang term in it:

 

Data = <<"{get,\"user\",\"wilson\",\"lname\"}">>.

 

Output: The Erlang term represented by the binary:

 

D = binary_to_list(Data),

{ok, Tokens, _} = erl_scan:string(D ++ "."),

{ok, Term} = erl_parse:parse_term(Tokens),

Term.

 

 

From: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] On Behalf Of Muhammad Yousaf
Sent: Wednesday, April 06, 2011 3:07 PM
To: comptekki@REDACTED; erlang-questions@REDACTED
Subject: [erlang-questions] Re: How to remove \ from string

 

 

Thank you i got your point but what i am trying to do is ,  remote computer
is sending me a data via socket like {get,"user","wilson","lname"}

but for some reason i cannot match it in case statement my output is 

 

im in none 

recieve Data from
socket:[255,251,31,255,251,32,255,251,24,255,251,39,255,253,

                          1,255,251,3,255,253,3]

im in none 

recieve Data from socket:"{get,\"user\",\"wilson\",\"lname\"}"

im in none 

recieve Data from socket:"\r\n"

 

 

Code is as fellow 

 

do_echo(Socket) ->

    case gen_tcp:recv(Socket, 0) of

        {ok, Data} ->

            D = binary_to_list(Data),

            case D of 

                {get,_,_,_} -> io:format("im
innnnnnn~n");%gen_tcp:send(Socket,erl_api:search());

                _Else -> io:format("im in none ~n")

            end,

            io:format("recieve Data from socket:~p~n",[D]),

            do_echo(Socket);

        {error, closed} ->

            ok

    end.

 

Any idea what i am doing wrong ??

 

 

 


Regards,

 

Muhammad Yousaf





> Date: Wed, 6 Apr 2011 12:44:29 -0600
> Subject: Re: [erlang-questions] Re: How to remove \ from string
> From: comptekki@REDACTED
> To: muhammad.yousaf@REDACTED
> CC: erlang-questions@REDACTED
> 
> On Wed, Apr 6, 2011 at 11:36 AM, Muhammad Yousaf
> <muhammad.yousaf@REDACTED> wrote:
> >
> > Thanks a lot but i only want to remove backslash not double quotes
> > for example
> > Val = <<"{get,\"user\",\"wilson\",\"lname\"}">> ,
> > i need Val= <<"{get,"user","wilson","lname"}">>
> > what i am doing with your help
> >
> > re:replace(Val,["\\"],"",[global, {return,list}]). getting error
> >
> > [X||X<-"{get,\"user\",\"wilson\",\"lname\"}",X=/=$\\].
> >
> 
> <snip>
> 
> 
> Another way to see what is going on is do this:
> 
> Y=binary_to_list(<<"{get,\"user\",\"wilson\",\"lname\"}">>).
> [io_lib:format("~c~w",[X, X])||X <- Y].
> 
> You'll see \" in the output, but the ascii numeric value for that
> character is 34.
> 
> Then if you go and look and see what 34 is on the ascii table below,
> you'll see it is ".
> 
> http://www.asciitable.com/
> 
> -wes

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110407/9391635e/attachment.htm>


More information about the erlang-questions mailing list