lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


#str in Lua returns the length in bytes of the string str. The same behavior is expected in LuaRT.

Iterating through a string in Lua using a for loop with the Length operator doesn't work for UTF8 encoded strings, especialy with characters that exceed ASCII encoding.
It's the same in LuaRT. You should use the string:len() method instead.

The behaviour might change in the future with users feedback.

So you should write in LuaRT :
for i = 1, str:len() do
local c = str:sub(i, i)
....
end



25 janvier 2021 13:14 "Egor Skriptunoff" <egor.skriptunoff@gmail.com> a écrit:
The following approach is widely used in Lua scripts:
for i = 1, #str do
local c = str:sub(i, i)
....
end
Will this code work in LuaRT?