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

Wes James comptekki@REDACTED
Wed Apr 6 23:50:04 CEST 2011


On Wed, Apr 6, 2011 at 2:07 PM, Muhammad Yousaf
<muhammad.yousaf@REDACTED> 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

<snip>

>
> 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.

Another option.  Skip the binary_to_list and do pattern matching like this:

...

                <<"{","g","e","t",_/binary>> -> io:format("im
innnnnnn~n");%gen_tcp:send(Socket,erl_api:search());

...

-wes



More information about the erlang-questions mailing list