Let's say I had this in a textbox or string:
Hello!
World
This is
a string
that doesn't
exist!
If I wanted to, say, print line 4, how would I go about doing that? There doesn't seem to be any straightforward way of doing this.
Let's say I had this in a textbox or string:
Hello!
World
This is
a string
that doesn't
exist!
If I wanted to, say, print line 4, how would I go about doing that? There doesn't seem to be any straightforward way of doing this.
You can use string.split to split new lines into seperate parts, then getting the 4th result.
Example:
local str = [[
hello
ok
yes
wanted
]]
print(string.split(str, "\n")[4])
-- \n meaning new line
string.split(<string> what string to split, <string> what part to split)
This should give a table containg
[1] = hello [2] = ok [3] = yes [4] = wanted
As string.split returns a table.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
good explanation