[erlang-questions] Binary:split and re:split woes
Robert Virding
robert.virding@REDACTED
Tue Dec 3 16:53:42 CET 2013
These two functions allow you give a pattern to split binaries (and lists in re) into a list of sub binaries. If the split pattern occurs at the beginning or end of the binary then you get empty parts at the beginning or end. So:
binary:split(<<" abc def ghi ">>, <<" ">>, [global]) ==>
[<<>>,<<"abc">>,<<"def">>,<<"ghi">>,<<>>]
This is fine and logical. Often you don't want these empty parts so there is a 'trim' options which removes them. But it only trims at the end and not at the beginning. So:
binary:split(<<" abc def ghi ">>, <<" ">>, [global,trim]) ==>
[<<>>,<<"abc">>,<<"def">>,<<"ghi">>]
This is stupid! Saying it it done like this Perl is hardly a good excuse for bad behaviour.
Sigh,
Robert
More information about the erlang-questions
mailing list