.char()
Published Sep 7, 2023Updated Sep 13, 2023
Contribute to Docs
In Lua, the string.char()
function is used to convert a decimal value to its internal character value.
Syntax
string.char(I)
In the above syntax, the identifier I
represents the decimal value which will be converted into a character.
Example 1
The following example uses the string.char()
function to convert different decimal values to their associated character values:
x = 10i = 0while i <= x dos = string.char(97 + i)print(s)i = i + 1end
This example results in the following output:
abcdefghijk
Example 2
The string.char()
function can take multiple arguments as well:
i = 97s = string.char(i, i+1, i+2, i+3)print(s)
This example results in the following output:
abcd
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.