lua first char of string
-- get the first character of a string
local myString = "Hello"
local firstChar = string.sub(myString, 1, 1)
print(firstChar)
- Declare a variable
myString
and assign the value "Hello" to it. - Declare a variable
firstChar
and use thestring.sub
function to get a substring ofmyString
starting at position 1 and ending at position 1. - Print the value of
firstChar
to the console.