So I know you can make multi-line strings with "[[ ]]" or "\", but my question is how do we split those to make single line string and putting it in a table? This is what I want to do
local MultiLine = "Hey!\ This string\ is a multi-line one!" local strings = {} --Your fix print(strings[1]) --Prints "Hey!" print(strings[2]) --Prints "This string" print(strings[3]) --Prints "is a multi-line one"
If you still don't understand, don't hesitate to ask :)
You can break a string into components by using patterns to find each desired chunk. String patterns follow a pretty simple format; it's just a matter of memorizing character classes, quantifiers, and some other specific mechanics. You can parse a string by using the gmatch
function as an iterator to a generic for, using a specified pattern to find every next match.
local function parse(s) local t = {}; for chunk in string.gmatch(s, "[^\n]+") do t[#t+1] = chunk; end; return t; end;
The string pattern [^\n]+
will find all characters between every new line. You can read more about string patterns here.