Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert binary UTF-8 string to string?

Is it possible to convert Erlang binary UTF-8 string (like <<"HELLO">>) to lowercase without converting it to list and back?

like image 205
Ivan Dubrov Avatar asked May 24 '11 16:05

Ivan Dubrov


People also ask

Is UTF-8 the same as binary?

To be clear: utf8 does not equal binary. The files are not identical. The UTF8 version is bigger. Press the "Raw" button, then you will see a difference.

How do I encode a string in UTF-8?

In order to convert a String into UTF-8, we use the getBytes() method in Java. The getBytes() method encodes a String into a sequence of bytes and returns a byte array. where charsetName is the specific charset by which the String is encoded into an array of bytes.


2 Answers

If you know how to lowercase unicode character and key words here are "without converting it to list and back", then the answer could be:

<< <<(unicode_to_lower(C))/utf8>> || <<C/utf8>> <= <<"HELLO">> >>.
like image 106
Victor Moroz Avatar answered Oct 10 '22 10:10

Victor Moroz


string:lowercase in Erlang 20 works with binaries:

1> string:lowercase(<<"HELLO">>).
<<"hello">>
like image 38
Facundo Olano Avatar answered Oct 10 '22 10:10

Facundo Olano