[erlang-questions] bug in binary:split with trim?

Wes James comptekki@REDACTED
Tue Jun 28 17:11:38 CEST 2011


On Tue, Jun 28, 2011 at 3:58 AM, Pablo Platt <pablo.platt@REDACTED> wrote:
> binary:split with the trim option doesn't remove empty results from the
> beginning of the binary:
>
> binary:split(<<"/a/b/">>, <<"/">>, [global, trim]).
> [<<>>,<<"a">>,<<"b">>]
> binary:split(<<"//a/b///">>, <<"/">>, [trim, global]).
> [<<>>,<<>>,<<"a">>,<<"b">>]
> Is this a bug?
> Thanks

Little more processing, but....


[list_to_binary(X) || X <- string:tokens(binary_to_list(<<"//a/b///">>),"/")].

[<<"a">>,<<"b">>]


or maybe like this:

[Result]=string:tokens(binary:split(<<"//a/b///">>, <<"/">>, [trim,
global]), [<<>>]).
[[<<"a">>,<<"b">>]]
11> Result.
[<<"a">>,<<"b">>]

-wes



More information about the erlang-questions mailing list