Hi this is my first post here hope you all are well. So Im just starting erlang and I ran into a problem im not sure how to tackle yet.
So I have a binary I am recieving in the form of
<<56, 23, 67, 34, 45, 78, 01, 54, 67, 87, 45, 53, 01, 34, 56, 78>>
My goal is to split it into a sub list (or binary if more efficient) based on the 01.
For example the above should come out looking like:
<<56, 23, 67, 34, 45, 78>> <<54, 67, 87, 45, 53>> <<34, 56, 78>>
-or-
[[56, 23, 67, 34, 45, 78], [54, 67, 87, 45, 53], [34, 56, 78]]
The 01 is the separating tag, it does not need to be included in the final output.
I have tried something as such: (PLEASE disregard if there is a better way)
parse1([]) -> [];
parse1(1) -> io:format("SOHSOHSOHSOHSOHSSOHSOHS");
parse1(Reply) -> parse1({Reply, []});
parse1({Reply, nxtParse}) ->
[H | T] = Reply,
case H of
_ when H > 1 ->
[H | nxtParse],
io:format("Reply 1 = ~p~n", [H]),
parse1({T, nxtParse});
_ when H == 1 ->
io:format("SOHSOHSOHSOHSOHSSOHSOHS");
[] ->
ok
end.
This isn't really clean at all and doesn't resemble at all what pro's write. Im sure Ill smack my head "duh" when someone clues me in.
I realize there is definitely more than one solution, but what is the BEST one. It seems ERL has so many BIF's and way to do things, just gotta find my way around I guess.
Thanks for the help guys -B