This session will teach you about splitting complex string of data separated with some characters. Lets assume that you have a string as House;home,40|Bed,20|Mirror,10. Now we will show you how to split each word and assigning each to a table.
local myString = "House;home,40|Bed,20|Mirror,10"
local myTable = {}
for word in string.gmatch(myString, '([^,|]+)') do
-- 'myTable' contains the data you need
myTable[#myTable+1]=word print( myTable[#myTable] )
end
Hence you will get the items as each table elements, as:
myTable[1] = House
myTable[2] = home
myTable[3] = 40
myTable[4] = Bed
myTable[5] = 20
myTable[6] = Mirror
myTable[7] = 10
No comments:
Post a Comment