Skip to content

Instantly share code, notes, and snippets.

@lucky
Created June 18, 2010 23:13
Show Gist options
  • Save lucky/444347 to your computer and use it in GitHub Desktop.
Save lucky/444347 to your computer and use it in GitHub Desktop.
% Contrary to the BIF, this splits on a character, not a position
% split_binary(<<1,2,3,4,5>>, 3) returns {<<1,2>>, <<4,5>>}
split_binary(Bin, C) when is_integer(C) -> split_binary(<<>>, Bin, C).
split_binary(Bin, <<>>, _) -> {Bin, <<>>};
split_binary(Head, <<T, Tail/binary>>, C) ->
case T of
C -> {Head, Tail};
_ -> split_binary(<<Head/binary, T>>, Tail, C)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment