How to get first character of string in Lua?
You can use string.sub()
to get a substring of length 1:
> s = "abc123"
> string.sub(s, 1, 1)
a
This also works for empty strings:
> string.sub("", 1, 1) -- => ""
You can also use this shorter variant:
s:sub(1, 1)