Hey guys,
I'm having a little problem, and I wont go in the details.. but basically...
I have, for example, local string1 = "1234567890"
and a local table1 = {}
I then want to split, and save the string in the table, so the table becomes like this:
local table = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}
So I can all the parts of the string seperatly.
Is there a way to do this?
And if yes, how?
Save a string as a table?
Started by Tjakka5, Jul 18 2013 06:32 AM
7 replies to this topic
#1
Posted 18 July 2013 - 06:32 AM
#2
Posted 18 July 2013 - 06:35 AM
Yah, you should look into serialize/unserialize
#3
Posted 18 July 2013 - 06:37 AM
I tought it had to do something with that, but when I tried something very basic with that...
Well, let your signature speak for me.
Well, let your signature speak for me.
#4
Posted 18 July 2013 - 06:42 AM
#5
Posted 18 July 2013 - 06:44 AM
Prog:11: Attempt to concatenate String and Nil.
The pic1 would be something like
13644291
16842974
41784614
74907414
80841456
local colors = {"colors.white", "colors.orange", "colors.magenta", "colors.lightBlue", "colors.yellow", "colors.lime", "colors.pink", "colors.gray", "colors.lightGray", "colors.cyan", "colors.purple", "colors.blue", "colors.brown", "colors.green", "colors.red", "colors.black"}
function printAppPic(x, y, file)
file = fs.open(file, "r")
imgLoad = file.readAll()
if (imgLoad ~= nil and loadString ~= "") then
imgLoadFull = {}
imgLoadFull = textutils.unserialize(imgLoad)
for i = 1, #imgLoadFull do
print("" ..imgLoadFull[i])
end
end
file.close()
end
printAppPic(1, 1, "pic1")
The pic1 would be something like
13644291
16842974
41784614
74907414
80841456
#6
Posted 18 July 2013 - 06:45 AM
textutils wont help here. Just do this:
This will loop through your whole string and put it in a table.
local str = "123456789"
local t = {}
for i = 1, str:len() do
table.insert( t, str:sub( i, i ) )
end
This will loop through your whole string and put it in a table.
#7
Posted 18 July 2013 - 06:49 AM
Edited out
#8
Posted 18 July 2013 - 06:50 AM
I think it works, thanks 
And yes, that's the full program.
And yes, that's the full program.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











