Parsing null terminated strings in a binary.
Thu Jan 13 09:58:44 CET 2005
Holy crap, why didn't I think of. Thanks Raimo, that helps a lot.
On 13 Jan 2005 08:50:03 +0100, Raimo Niskanen <raimo@REDACTED> wrote:
> Parse the binary in a loop something like this (untested):
> z_split(<<B1:N/binary,0,B2/binary>>, N) ->
> z_split(<<B1:N/binary>>, N) ->
> z_split(<<_:N/binary,_/binary>>=B, N) ->
> z_split(B, N+1).
> This will not build any sub-binaries until the zero is found.
> cyberlync@REDACTED (Eric Merritt) writes:
> > Guys,
> > I have a need to parse out a series of null terminated fields a
> > binary. The easiest way to do this is to simply traverse the binary
> > using bit syntax until a null byte occurs. However, I believe this
> > would be less then efficient as a new binary would be created for each
> > byte matched. Aside from created a C port to actually do the parsing
> > do any of you have any ideas on how to do this efficiently?
> > Thanks,
> > Eric
> > --
> > I'm a programmer, I don't have to spell correctly; I just have to
> > spell consistently
> / Raimo Niskanen, Erlang/OTP, Ericsson AB
I'm a programmer, I don't have to spell correctly; I just have to
More information about the erlang-questions