You'd have to go for a less robust function that utilizes string.find to correctly find the separator character.
local function split(inputString, separatorCharacter)
if (type(separatorCharacter) ~= "string") then
separatorCharacter = "\n"
end
local returnTable = {}
local i = 1
--#We're going to be editing our input string, so we need to know when we're done
while (inputString ~= "") do
local start,endNum = string.find(inputString,separatorCharacter)
if (start == nil) then
returnTable[i] = inputString
inputString = ""
else
if (start == 1) then
returnTable[i] = ""
else
returnTable[i] = inputString:sub(1,start-1)
end
inputString = inputString:sub(endNum+1)
end
i = i + 1
end
return returnTable
end
Edit: Minor edit to the code so far, i used the variable named end, which is a reserved word and I'm dumb.
Edit2: Lua, why you use ~= and not !=
Edit3: Sigh.. This is being more trouble than I'd love to admit
Edit4: Apparently inputstring:find didn't want to work correctly. It saved the old inputstring as the function.
So it ran once, where inputstring was "a\nb\n\n\c" and then when it ran the second time, even though inputstring changed to "b\n\nc" it thought it was still "a\nb\n\n\c" and gave the location of the 2nd newline
Edited by Dragon53535, 04 April 2016 - 10:51 PM.