Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to concat two utf8 string in erlang?

I have two variable as below:

A = <<"سعید"/utf8>>,
B = <<"حیدری"/utf8>>,

how can i concat A and B ?

C = <<A/utf8, B/utf8>>.

line above returns exception error: bad argument

like image 898
Saeed Avatar asked Mar 08 '23 04:03

Saeed


1 Answers

utf8 is just encoding. It is binary as any other binary:

1> A = <<"سعید"/utf8>>,
1> B = <<"حیدری"/utf8>>,
1> C = <<A/bytes, B/bytes>>.
<<216,179,216,185,219,140,216,175,216,173,219,140,216,175,
  216,177,219,140>>
2> io:put_chars([C, $\n]).
سعیدحیدری
ok

P.S.: The result is shown reversed because of web browser behavior. It is shown in correct order in the console.

like image 54
Hynek -Pichi- Vychodil Avatar answered Mar 17 '23 03:03

Hynek -Pichi- Vychodil