Smart way to trim a binary?

Steve Davis steven.charles.davis@REDACTED
Wed Jun 24 16:46:45 CEST 2009


On Jun 24, 9:03 am, Seth Falcon <s...@REDACTED> wrote:
> * On 2009-06-24 at 14:40 +0200 Ulf Wiger wrote:
>
> > BTW, regarding the trimming of binaries, perhaps someone
> > with more regexp skill could improve on this:
>
> > 1> re:split(<<"  \tabc\t  ">>, "[(^\\h*)(\\h$)]",[trim]).
> > [<<>>,<<>>,<<>>,<<"abc">>]
>
> Perhaps:
>
> trimre(Bin) ->
>     re:replace(Bin, "^\\s+|\\s+$", "", [{return, binary}, global]).
>
> + seth
>

Smarts+ :) Many thanks Ulf/Seth.

Thanks also to everyone else -- as always, I learned a few things from
reading the other solutions/approaches.

BR
Steve



More information about the erlang-questions mailing list