<div dir="ltr">You may want to move the currency to the front of the bitstring and then pattern match it like: currency_to_credits({cur, <<"EUR", Amount/binary>>}, Acc) ...<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Dec 9, 2020 at 1:49 PM Java House <<a href="mailto:java4dev@gmail.com">java4dev@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">there is a typo in the example<div><div>currrency_to_credits({cur, <<
Value
, "CHF">>}, Acc)</div><div> when Value >= <<"1000">>, Value =< <<"10000">> -><br></div><div> {chf, Acc +
Value
};<br></div><div><div>currrency_to_credits({cur, <<
Value
, "EUR">>}, Acc)</div><div> when Value >= <<"1000">>, Value =< <<"10000">> -><br></div><div> {eur, Acc +
Value
};</div></div><div><div>currrency_to_credits({cur, <<
Value
, "US">>}, Acc)</div><div> when Value >= <<"1000">>, Value =< <<"10000">> -><br></div><div> {us, Acc +
Value
};</div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Στις Τετ, 9 Δεκ 2020 στις 7:17 μ.μ., ο/η Java House <<a href="mailto:java4dev@gmail.com" target="_blank">java4dev@gmail.com</a>> έγραψε:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello all<div><br></div><div>I am learning Erlang and have stuck to the following problem.</div><div>How to write a function with pattern matching when the parameter is a binary string.</div><div><br></div><div>I have a list of binary strings e.g.</div><div><<3123CHF>></div><div><<341424343EUR>></div><div><<14143US>></div><div><br></div><div>I am trying to create a function that matches according to a pattern.</div><div><br></div><div>currrency_to_credits({cur, <<A, "CHF">>}, Acc)</div><div>
when Value >= <<"1000">>, Value =< <<"10000">> -><br></div><div> {chf, Acc + A};<br></div><div><div>currrency_to_credits({cur, <<A, "EUR">>}, Acc)</div><div>
when Value >= <<"1000">>, Value =< <<"10000">> -><br></div><div> {eur, Acc + A};</div></div><div><div>currrency_to_credits({cur, <<A, "US">>}, Acc)</div><div>
when Value >= <<"1000">>, Value =< <<"10000">> -><br></div><div> {us, Acc + A};</div></div><div><br></div><div>But this does not seem to be the right way.</div><div>How can I create a pattern for binary string?</div><div>will it work better for list string? How?</div><div><br></div><div>Thank you</div><div>Nikolas</div></div>
</blockquote></div>
</blockquote></div>