Haystees
(Haystees)
July 1, 2023, 3:26am
#1
As the topic name suggests.
Right now, i’m using string.find()
and trying to store the start and end values of a string.
Is there a better way I can do this other than this?:
local Table = {
TupleTable = {}
}
local Start, End = string.find(String, "find")
Table.TupleTable = {Start = Start, End = End}
1 Like
p49p0
(Panthera)
July 1, 2023, 3:32am
#2
question unclear. string.find doesn’t store anything
You can use table.unpack
on an array and make it act like a tuple:
local tab = {}
tab.tupleTable = {string.find(str, pattern)}
local start, finish = table.unpack(tab.tupleTable)
print(table.unpack(tupleTable)) --> prints start, finish
Although, why would you need to store tuples anyway?
1 Like
blokav
(blokav)
July 1, 2023, 3:55am
#4
You could do something like:
Table.TupleTable = table.pack(string.find(String, "find"))
However that would give you the results in an array format, so you’d have to retrieve them with numbers 1 and 2 rather than Start and End.
1 Like
Haystees
(Haystees)
July 1, 2023, 3:57am
#5
I didn’t know about either table.pack
or table.unpack
, thank you to both of you.
system
(system)
Closed
July 15, 2023, 3:58am
#6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.