How to get char code in LUA?

Hi friends
Is there any way to get Character code from string in defold using LUA? ( or just one char of string )
something like what this website do

I think you need string.byte

1 Like

Thanks Denis
It works on english letters but for persian letters it’s different, it gives me just one part of the code, for example persian char “ا” ( alef ) ascii code is “216 167” but it gives me just “216” (first part).

print(string.byte( "ا"))

this function returns ascii code, anyway to get utf-8 or decimal? or converting ascii?

Try

local c = "ا"
print(string.byte(c,1,2))
1 Like

There are UTF8 Lua modules you can look at:

1 Like

Thanks Friends, I’ll try them. I’m trying to use persian suitable and easy in defold without using any extra converter. I don’t know whats the correct way to achieve this but i try to find something.

I think the UTF 8 module I linked is the way to go if you need to manipulate strings with UTF8 encoded text. It will be able to deal with characters that take up more than a single byte.

1 Like