Where can I get the number codes from the ".char" functions?

Hello, so if you are confused by the Topic Title, I am wondering wondering what exactly are the number codes for the functions like utf8.char() and string.char() where they give you a specific character from the number given, like such:

local random = math.random(65, 90) -- random number

-- random character?
string.char(random) -- 'string'
utf8.char(random)   -- 'utf8'

I’m not sure if they are already listed or if I’m missing something but I want to know what exactly they mean so I can use it properly.

Where can I find this information?

You can look at the ASCII chart for the string library here: ASCII Table - ASCII codes,hex,decimal,binary,html

And here for utf8: Unicode characters table


UTF-8 has a lot more to it since it encodes a lot more characters and symbols than ASCII.

1 Like

ah, well that makes sense, thank you

Also string.byte/utf8.codepoint

string.byte will only return the first byte so in the case of multi-byte characters (i.e. arbitrary input or non-English languages) use the utf8 library, not string.

print(utf8.codepoint('h')) --> 104
print(utf8.char(104)) --> h

print(string.byte('h')) --> 104
print(string.char(104)) --> h

-----

print(utf8.codepoint('象')) --> 35937, ok
print(utf8.char(35937)) --> 象, ok
print(string.byte('象')) --> 232, control character (first byte of 象)
print(string.char(35937)) --> error
1 Like

Thanks, but I already know that, I was just asking where I could find the number code for the characters for string.char and utf8.char

Edit: missread, but yeah, you should.

I meant as in something to reference, but i know that.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.