Jump to content




Save a string as a table?


  • You cannot reply to this topic
7 replies to this topic

#1 Tjakka5

  • Members
  • 256 posts

Posted 18 July 2013 - 06:32 AM

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?

#2 Apfeldstrudel

  • Members
  • 161 posts

Posted 18 July 2013 - 06:35 AM

Yah, you should look into serialize/unserialize :D

#3 Tjakka5

  • Members
  • 256 posts

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.

#4 Apfeldstrudel

  • Members
  • 161 posts

Posted 18 July 2013 - 06:42 AM

:D Error? What error?


#5 Tjakka5

  • Members
  • 256 posts

Posted 18 July 2013 - 06:44 AM

Prog:11: Attempt to concatenate String and Nil.

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 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 18 July 2013 - 06:45 AM

textutils wont help here. Just do this:

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 Apfeldstrudel

  • Members
  • 161 posts

Posted 18 July 2013 - 06:49 AM

Edited out

#8 Tjakka5

  • Members
  • 256 posts

Posted 18 July 2013 - 06:50 AM

I think it works, thanks :)

And yes, that's the full program.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users