Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Split A Sting In Lua

there's a better function to use in :

id : 2xgl9090

This works, but the other is more robust

Splitting a string in lua can be done by matching everything except for the separator in a [TODO: Code shorthand span ] capture group like this :

lua
local line = "alfa bravo charlie"

local words = {}
for word in string.gmatch(line, "%S+") do
    table.insert(words, word)
end

print(words[1])
print(words[2])
print(words[3])
results start

Old Notes

These are older notes that I need to go back and look over

via : http : //lua - users.org/wiki/SplitJoin

Another approach

lua
function mysplit (inputstr, sep)
        if sep == nil then
                sep = "%s"
        end
        local t={}
        for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
                table.insert(t, str)
        end
        return t
end

input_string = 'this is it'

base_table = mysplit(input_string, " ")

for i=2, #base_table do
        print(base_table[i])
end

via : https : //stackoverflow.com/a/7615129/102401