Получение символа из строки

Простые типы / Символьный тип

local text = "ABC"

-- sub(i, i) is one char, positions go from 1
local char_a = text:sub(1, 1)
-- char_a = A
local char_b = text:sub(2, 2)
-- char_b = B
local char_c = text:sub(3, 3)
-- char_c = C

-- Position -1 is the last char
local char_last = text:sub(-1)
-- char_last = C

-- All chars into an array
local chars = {}
for char in text:gmatch(".") do
  chars[#chars + 1] = char
end
-- chars = A, B, C

-- A string is not a table of chars:
-- text[1] is nil, not an error
local indexed = text[1]
-- indexed = nil

print("char_a = " .. char_a)
print("char_b = " .. char_b)
print("char_c = " .. char_c)
print("char_last = " .. char_last)
print("chars = " .. table.concat(chars, ", "))
print("indexed = " .. tostring(indexed))