• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved Problem with string/table...

Dantarrix

Member
Joined
Aug 27, 2010
Messages
546
Reaction score
18
Location
Stgo, Chile
Well, I'm getting a value from XML:

"{1, 2, 3, 4, 5}"

I want to have it as a table like this:

{1, 2, 3, 4, 5}

How can I do that?
How can I delete those symbols? (" ")

Im getting it with a string:match...

Thank you...

Sorry for bad english...
 
Last edited:
You want to get that string and turn it into an actual table with integer values 1, 2, 3, 4, 5?
If so, here's what I managed to do: http://codepad.org/8Sb0rSU8

Lua:
stringInput = "{1,2,3,4,5}"

t = {}

for i = 1, 5 do
table.insert(t,string.match(stringInput, "%d+", i+i))
end

for i = 1, 5 do
print(t[i])
end
I understand the length of the for loop is pre-defined, I just can't think of a way how I could get the number of integers in a string.
I tried using this:
Lua:
string.gsub("{1,2,3,4,5}","%d", function(d) return string.len(d) end)
Here is what the output looks like: http://codepad.org/wDnm1xxS
I'm not sure if that is what you're looking for.
 
Last edited:
Not sure about this (I never tried), but i think you can use something like this
Lua:
local input = "{1, 2, 3, 4, 5}"
local table = loadstring(input)

for i = 1, #table do
	print(table[i])
end
 
@Darkhoas
Almost, it should be used like this in this case:
Lua:
local input = "{1, 2, 3, 4, 5}"
local table = loadstring("return " .. input)()
 
for i = 1, #table do
	print(table[i])
end
 
This one is working
Lua:
	local input = "{1, 2, 3, 4, 5}"
	local t = "local table = " .. input .. " return table"
	local a = loadstring(t)
	for i = 1, #a() do
		print(a()[i])
	end
 
Back
Top