<div dir="ltr"><div>Hi,</div><div><br></div><div>Short version without input validation, will crash if the input does not match the expected values:</div><div><br></div><div>currency(<<"CHF">>) -> chf;<br>currency(<<"EUR">>) -> eur;<br>currency(<<"US">>) -> us.<br><br>currrency_to_credits({cur, String}, Acc) -><br> {Value, Currency} = string:to_integer(String),<br> {currency(Currency), Acc + Value}.<br></div><div><br></div><div>Andreas</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Mi., 9. Dez. 2020 um 19:49 Uhr schrieb Java House <<a href="mailto:java4dev@gmail.com">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">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><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><p><span style="font-family:verdana,geneva,sans-serif;font-size:10pt">Andreas Schultz</span></p>
<p><span style="font-family:verdana,geneva,sans-serif;font-size:10pt">-- </span></p>
<p><span style="font-family:verdana,geneva,sans-serif;font-size:8pt">Principal Engineer</span></p>
<p><span style="font-family:verdana,geneva,sans-serif;font-size:10.6667px"> t: +49 391 819099-224 </span></p>
<p><span style="font-family:verdana,geneva,sans-serif;font-size:8pt"><span style="font-family:verdana,geneva,sans-serif;font-size:10.6667px"></span></span></p>
<p><span style="font-family:verdana,geneva,sans-serif;font-size:8pt">------------------------------- enabling your networks -----------------------------</span></p>
<table style="height:142px;width:550px">
<tbody>
<tr style="height:30px">
<td style="width:146px;height:30px">
<p><span style="font-family:verdana,geneva,sans-serif;color:rgb(34,34,34);font-size:8pt">Travelping GmbH <br></span><span style="font-family:verdana,geneva,sans-serif;color:rgb(34,34,34);font-size:8pt">Roentgenstraße 13<br></span><span style="font-family:verdana,geneva,sans-serif;color:rgb(34,34,34);font-size:8pt">39108 Magdeburg<br></span><span style="font-family:verdana,geneva,sans-serif;color:rgb(34,34,34);font-size:8pt">Germany<br><br></span></p>
</td>
<td style="width:162px;height:30px">
<p style="color:rgb(34,34,34);font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:small;text-align:justify"><span style="font-family:verdana,geneva,sans-serif;font-size:8pt">t: +49 391 819099-0<br></span><span style="font-family:verdana,geneva,sans-serif;font-size:8pt">f: +49 391 819099-299</span></p>
<p style="color:rgb(34,34,34);font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:small;text-align:justify"><span style="font-family:verdana,geneva,sans-serif;font-size:8pt">e: <a href="mailto:info@travelping.com" target="_blank">info@travelping.com</a><br></span><span style="font-family:verdana,geneva,sans-serif;font-size:8pt">w: <a href="https://www.travelping.com/" target="_blank">https://www.travelping.com/</a></span></p>
</td>
</tr>
<tr style="height:17px">
<td style="width:146px;height:17px"><span style="font-size:8pt;font-family:verdana,geneva,sans-serif">Company registration: Amtsgericht Stendal <br>Managing Director: Holger Winkelmann<br></span></td>
<td style="width:162px;height:17px"><span style="font-size:8pt;font-family:verdana,geneva,sans-serif">Reg. No.: HRB 10578<br>VAT ID: DE236673780</span></td>
</tr>
</tbody>
</table></div>