Paste number 69680: split binary by converting to list

Index of paste annotations: 1

Paste number 69680: split binary by converting to list
Pasted by: mmagin
When:1 year, 9 months ago
Share:Tweet this! | http://paste.lisp.org/+1HRK
Channel:None
Paste contents:
Raw Source | XML | Display As
split_binary_on_as_string(Bin, Match) ->
    Str = binary_to_list(Bin),
    Offset = string:chr(Str, Match),
    {list_to_binary([string:substr(Str, 1, Offset-1)]), 
     list_to_binary([string:substr(Str, Offset+1)])}.

Annotations for this paste:

Annotation number 1: less dumb version
Pasted by: mmagin
When:1 year, 9 months ago
Share:Tweet this! | http://paste.lisp.org/+1HRK/1
Paste contents:
Raw Source | Display As
split_binary_match(Bin, Match) ->    
    Str = binary_to_list(Bin),
    Offset = string:chr(Str, Match),
    {Some, <<_Char, Rest/binary>>} = split_binary(Bin, Offset-1),
    {Some, Rest}.

Colorize as:
Show Line Numbers
Index of paste annotations: 1

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.