Smart way to trim a binary?

Steve Davis <>
Wed Jun 24 02:21:45 CEST 2009

I have this feeling that there's a much smarter way to trim a string
presented as a binary rather than this (mostly found in couch_util)...

trim(Bin) when is_binary(Bin) ->
trim(String) when is_list(String) ->
    String2 = lists:dropwhile(fun is_whitespace/1, String),
    lists:reverse(lists:dropwhile(fun is_whitespace/1, lists:reverse

is_whitespace($\s)-> true;
is_whitespace($\t)-> true;
is_whitespace($\n)-> true;
is_whitespace($\r)-> true;
is_whitespace(_Else) -> false.

...anybody have a nice way of doing this?


More information about the erlang-questions mailing list