[erlang-questions] map over bitstring
Jesper Louis Andersen
Thu Oct 21 22:10:23 CEST 2010
On Thu, Oct 21, 2010 at 9:56 PM, rgowka1 <rgowka1@REDACTED> wrote:
> Hi -
> How do I map a function over a bitstring without converting into string or list.
> For example - how can I replace << "a" >> with << "X" >> and any other
> character to << "Y" >>??
> InBin = << "abcaa" >>
> OutBin = << "XYYXX" >>
The trick is Binary Comprehensions or by using the (R14B) binary
module. Here is a solution using the Binary Comprehensions:
3> << <<case X of $a -> $X; _ -> $Y end>> || <<X>> <= <<"abcaa" >> >>.
More information about the erlang-questions