<div dir="ltr">You could reverse it first and then match on the reversed symbol:<div><br></div><div>Data from the provider:</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Reversed = list_to_binary(lists:reverse(binary_to_list(<<"1234EUR">>))).</blockquote><div><div><br></div><div> </div>Reverse the Currency name in the match<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> currency_to_credits({cur, <<"RUE", Reversed/binary>>}, Acc) -><br> {eur, Acc + A};</blockquote><div><br></div><div>Probably not the most performant but at least it solves the problem.</div><div><br></div><div>Best,</div><div>nisbus </div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Dec 10, 2020 at 8:16 AM 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">Hi<div><br></div><div>yes the binary string is of the format <<"xxx">></div><div><blockquote type="cite"><div class="gmail_quote"><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"><div><<"3123CHF">><br></div><div><<"341424343EUR">><br></div><div><<"14143US">></div></div></blockquote></div></blockquote> Thank you for the answer.<br></div><div>So is there any other way? </div><div>erlang provides the binary_to_list, is there any way to achieve the same with a list becasue I tried similare patterns with list and it does not work e.g</div><div>[V|T] this will always match the first character of the string to V</div><div>and [V|"CHF"] does not work neither.</div><div><br></div><div>Best</div><div>Nikolas</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Στις Τετ, 9 Δεκ 2020 στις 7:58 μ.μ., ο/η kuna.prime <<a href="mailto:kuna.prime@protonmail.com" target="_blank">kuna.prime@protonmail.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>HI, <br></div><div><br></div><div>first of all binary string is of form <<"3123CHF">> and not <<3123CHF>> i'm just stating it in case there was a mistake in the first mail <br></div><div><br></div><div>to answer your questio in order to pattern match you need to know the size of field you are matching so <br></div><div><br></div><div><<X:4/binary, "CHF">> = <<"3123CHF">>. <br></div><div><br></div><div>will match fist 4 bytes and interpret that as new binary (X).<br></div><div><br></div><div><div><br></div><div>Sent with <a href="https://protonmail.com" target="_blank">ProtonMail</a> Secure Email.<br></div></div><div><br></div><div>‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐<br></div><div> On Wednesday, December 9, 2020 7:28 PM, Java House <<a href="mailto:java4dev@gmail.com" target="_blank">java4dev@gmail.com</a>> wrote:<br></div><div> <br></div><blockquote type="cite"><div dir="ltr"><div>there is a typo in the example<br></div><div><div>currrency_to_credits({cur, <<
Value
, "CHF">>}, Acc)<br></div><div> when Value >= <<"1000">>, Value =< <<"10000">> -><br></div><div> {chf, Acc +
Value
};<br></div><div><div>currrency_to_credits({cur, <<
Value
, "EUR">>}, Acc)<br></div><div> when Value >= <<"1000">>, Value =< <<"10000">> -><br></div><div> {eur, Acc +
Value
};<br></div></div><div><div>currrency_to_credits({cur, <<
Value
, "US">>}, Acc)<br></div><div> when Value >= <<"1000">>, Value =< <<"10000">> -><br></div><div> {us, Acc +
Value
};<br></div></div></div></div><div><br></div><div class="gmail_quote"><div dir="ltr">Στις Τετ, 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"><div>Hello all<br></div><div><br></div><div>I am learning Erlang and have stuck to the following problem.<br></div><div>How to write a function with pattern matching when the parameter is a binary string.<br></div><div><br></div><div>I have a list of binary strings e.g.<br></div><div><<3123CHF>><br></div><div><<341424343EUR>><br></div><div><<14143US>><br></div><div><br></div><div>I am trying to create a function that matches according to a pattern.<br></div><div><br></div><div>currrency_to_credits({cur, <<A, "CHF">>}, Acc)<br></div><div>
when Value >= <<"1000">>, Value =< <<"10000">> -><br></div><div> {chf, Acc + A};<br></div><div><div>currrency_to_credits({cur, <<A, "EUR">>}, Acc)<br></div><div>
when Value >= <<"1000">>, Value =< <<"10000">> -><br></div><div> {eur, Acc + A};<br></div></div><div><div>currrency_to_credits({cur, <<A, "US">>}, Acc)<br></div><div>
when Value >= <<"1000">>, Value =< <<"10000">> -><br></div><div> {us, Acc + A};<br></div></div><div><br></div><div>But this does not seem to be the right way.<br></div><div>How can I create a pattern for binary string?<br></div><div>will it work better for list string? How?<br></div><div><br></div><div>Thank you<br></div><div>Nikolas<br></div></div></blockquote></div></blockquote><div><br></div></blockquote></div>
</blockquote></div>