Say I have a string:
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ul !
I want to split it into:
{ "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", "u", "l", " ", "!", " " }
This is my current code:
local function splitIntoDuplicates(str)
local match = str:sub(1, 1)
local i = 2
local j = 1
local duplicates = {""}
while i <= #str do
if str:sub(i, i) == match then
duplicates[j] ..= str:sub(i, i)
else
match = str:sub(i, i)
j += 1
duplicates[j] = ""
end
i += 1
end
return duplicates
end
It works for the first part, but then everything else just becomes empty strings:
{ [1] = "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", [2] = "", [3] = "", [4] = " ", [5] = "" }
The code is horribly hacky in the first place.
Is there a better method, perhaps with string matching?
