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

Richard O'Keefe ok@REDACTED
Thu Apr 7 03:22:26 CEST 2011


On 7/04/2011, at 8:07 AM, Muhammad Yousaf wrote:

> 
> 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());
                  ^^^^

Binary to list gives you a *list* whose elements are *character codes* (integers).
{get,_,_,_} is a tuple pattern, not a list pattern.
get is an atom, not a character code.

If you want Erlang terms, why isn't the remote computer sending you the
binary representation of a term?

>                 _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
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list