Invalid Elixir String

I tried the following code in iex:

iex(13)> String.valid?(<<128>>)
false
iex(14)> String.valid?(<<191>>)
false

Why are strings not valid?

+4
source share
1 answer

As Ramon Snire said, you need to use utf8. In the getting started guide:

A string is a UTF-8 encoded binary. To understand exactly what we mean by this, we need to understand the difference between bytes and code points.

...

- . UTF-8 . , UTF-8 , , , , , UTF-8.

<<128 :: utf8>> |> String.valid? # => true

: , char

+2

Source: https://habr.com/ru/post/1628704/


All Articles