Currently I work on a project within the game Minecraft and OpenComputers. The main coding language is Lua.
Now, I need to find a nice solution to iterate through a string.
My current solution looks like this:
local config = "key1=type1\nkey2=type2\nkey3=type3"
local lines = {}
while true do
local length = config:len()
local s, f = config:find("\n")
if s ~= nil then
table.insert(lines, config:sub(1, s-1))
config = config:sub(f+1, length)
else
table.insert(lines, config)
break
end
end
In this example I have a static string in the variable config
but in the real code I read the lines from a config file.
My solution works, but I think it can be cleaner. Is there a cleaner solution?