[erlang-questions] string:strip/3 don't work right striping

Bengt Kleberg <>
Wed Jan 19 09:00:31 CET 2011


Greetings,

While I can not see all space that you want to delete in the input (it
would be helpful if you provided " at the beginning and the end) I can
guess that you have two \n at the end of each line. If you want to
delete any leading and/or trailing blanks (space) then string:strip/1
would be a good choice.
Given a better description of the input, and what you want to do with,
it might result in a better suggestion.


bengt

On Wed, 2011-01-19 at 07:48 +0100, shk wrote:
> Hello,
> 
> I receive data by socket in tcp:
> 
> receive_loop(Socket) ->
>     case gen_tcp:recv(Socket, 0) of
> 	 {ok, Data} ->
> 	    ReParseData = string:strip(string:to_lower(Data), both, $.),
> 	    io:format(ReParseData, []),
> 	    case ReParseData of
> 		"quit\r\n" ->
> 	          gen_tcp:send(Socket, "quit \r\n"),
> 		  gen_tcp:close(Socket);
> 	        _ ->
> 		  io:format(Data, []),
> 		  receive_loop(Socket)
> 	     end;
> 	 {error, closed} ->
> 	    ok
>     end.
> 
> if I send .........................Hello
> ......................................
> I got in shell:
> >Hello ......................................
> 
> How can i correctly delete space from left and right in stirng?
> 
> Thank you.



More information about the erlang-questions mailing list