The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Split A Sting In Lua

TODO: Pull subtitle into page object

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 `.gmatch()`` capture group like this:

Code
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
alfa
bravo
charlie

Old Notes

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

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

Another approach

code_start_default_section code_end_default_section

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

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Split A Sting In Lua

-- warning 

there's a better function to use in:

id: 2xgl9090

This works, but the other is more robust


-- p

Splitting a string in lua can be done by 
matching everything except for the separator
in a `.gmatch()`` capture group like this:

-- code
-- 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/

alfa
bravo
charlie

-- /results

-- h3

Old Notes

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


-- p

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

-- p

Another approach

-- code/
-- 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

-- /code

-- p

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


-- categories
-- Miscellaneous

-- metadata
-- date: 2021-06-20 19:58:06
-- id: 20eocfge
-- status: scratch
-- type: post
-- SCRUBBED_NEO: false
-- site: aws