Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Spliting a string into table by new line?

Soo what im trying to do is split a string with multiple lines into a table with each line. soo i searched on the wiki and it seems like i need to use the %s pattern the problem is that from my understanding that pattern is also for spaces is there a way for new lines only?

Im probably an idiot as i never use string patterns for anything

1 answer

✓ Accepted answer

For this you will have to do some patternizing, and it's a bit hard to do, but this will do.


function linesplit(inputstr)
        local t={} ; i=1
        for str in string.gmatch(inputstr, "([^\n]+)") do
                t[i] = str
                i = i + 1
        end
        return t
end

There's unicode symbols that you can use when using patterns, such as "\n" which is new line. Notepad uses "\t", which is also another way of new line.

If you'd ever like to use a space, you have to use "%s".

You should go check some Unicode symbols and Patterns here: http://lua-users.org/wiki/SplitJoin

2 comments

2

\t is a tab

0

Thanks! I will check it out when i have time :)

This discussion is preserved as it was. New answers, comments, and votes are closed.