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

23 views
Skip to first unread message

Pablo Platt

unread,
Jun 28, 2011, 5:58:46 AM6/28/11
to erlang-q...@erlang.org
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

Ahmed Omar

unread,
Jun 28, 2011, 6:43:42 AM6/28/11
to Pablo Platt, erlang-q...@erlang.org
According to documentation it's not
trim
Removes trailing empty parts of the result (as does trim in re:split/3)

_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions




--
Best Regards,
- Ahmed Omar
Follow me on twitter

Pablo Platt

unread,
Jun 28, 2011, 8:20:07 AM6/28/11
to Ahmed Omar, erlang-q...@erlang.org
Is there a reason to make it work only for trailing empty parts but not for all empty parts?


From: Ahmed Omar <spawn...@gmail.com>
To: Pablo Platt <pablo...@yahoo.com>
Cc: "erlang-q...@erlang.org" <erlang-q...@erlang.org>
Sent: Tuesday, June 28, 2011 1:43 PM
Subject: Re: [erlang-questions] bug in binary:split with trim?

Wes James

unread,
Jun 28, 2011, 11:11:38 AM6/28/11
to Pablo Platt, erlang-q...@erlang.org

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

Hynek Vychodil

unread,
Jun 29, 2011, 4:28:13 AM6/29/11
to Wes James, erlang-q...@erlang.org
Why not simply?
[X || X<- binary:split(<<"//a/b///">>, <<"/">>, [trim, global]), X=/=<<>>]

--
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill
your boss.  Be a data hero!
Try GoodData now for free: www.gooddata.com

Reply all
Reply to author
Forward
0 new messages