Help converting string into seperate strings

Post Reply
DuskyByte
Posts: 2
Joined: Mon Apr 12, 2021 7:23 pm

Help converting string into seperate strings

Post by DuskyByte »

Trying to turn what I get back from the who list in matches[2] into a table.
The list looks like this: Chris, David, Edward and Frank.
However, when I run it through the code I get something like:
Chris
D
vi
E
w
r
Fr
k

Thoughts?

Code I am using for testing now:

delim = {",", "and"}
s = matches[2]
p = "[^"..table.concat(delim).."]+"
for w in s:gmatch(p) do
echo("\n" .. w)
end

DuskyByte
Posts: 2
Joined: Mon Apr 12, 2021 7:23 pm

Re: Help converting string into seperate strings

Post by DuskyByte »

For those looking for a solution to this same issue. This is how I got it to work:
delim = {",", "."}
s = matches[2]:gsub(" and ", ", ")
s = s:gsub(", ", ",")
p = "[^" .. table.concat(delim) .. "]+"
for w in s:gmatch(p) do
echo("\n" .. w)
end

Post Reply