Bertaud
Bertaud

Reputation: 2918

syntax of binary:split with multiple patterns

What is the correct syntax when we use multiple patterns ?

test3()->
    test4(<<"1234567890">>).
test4(A)->
    X = binary:split(A,[<<"3">>,<<"8">>]),
    X.

[<<"12">>,<<"4567890">>]

I was expected 3 elements!

Upvotes: 1

Views: 168

Answers (1)

Alin
Alin

Reputation: 818

In order to get 3 elements, you should use the split/3 function and to specify the global option ("Repeats the split until the Subject is exhausted"):

binary:split(<<"1234567890">>,[<<"3">>,<<"8">>],[global]).

and you'll get:

[<<"12">>,<<"4567">>,<<"90">>]

More on this, in the official doc: http://www.erlang.org/doc/man/binary.html#split-3

Hope it helps.

Upvotes: 3

Related Questions