[erlang-questions] bit syntax or tokens ?
Robert Virding
rvirding@REDACTED
Sat Jul 3 00:06:10 CEST 2010
Another alternative is to do:
<<A:3/binary,_:8,B:2/binary,_:8,G/binary>> = S.
which will give binaries A, B and G. It is, however, a very static way
of doing it. Using the new binary module as Jesper suggests is much
more dynamic and adaptable. While you can put what you want into a
binary the bit syntax was never really designed for string fields,
especially not dynamic ones, as you can't search with it.
How much do you know about the substrings and what are you going to do
with them once you have got them? This can also influence how you
extract them.
Robert
On 2 July 2010 23:38, Jesper Louis Andersen
<jesper.louis.andersen@REDACTED> wrote:
> On Fri, Jul 2, 2010 at 11:32 PM, info <info@REDACTED> wrote:
>> Given a string S = <<"ABC,DE,FGH">>.
>> I do
>> <<Alpha:24,_:8,Beta:16,_:8,Gamma:24>> = S.
>> and
>> Alpha. gives 4276803
>
> This is an excellent case for the new R14A/EEP-31 binary module,
> presumed I understand your question:
>
> 3> binary:split(<<"ABC,DE,FHG">>, <<",">>).
> [<<"ABC">>,<<"DE,FHG">>]
>
>
> --
> J.
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>
More information about the erlang-questions
mailing list