开发者

syntax of binary:split with multiple patterns

What is the correct syntax when we use multiple patterns ?

test3()->
    test4(<<"12345开发者_JAVA百科67890">>).
test4(A)->
    X = binary:split(A,[<<"3">>,<<"8">>]),
    X.

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

I was expected 3 elements!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜