Jump to content




turning table data into one string


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

#1 ETHANATOR360

  • Members
  • 423 posts
  • Locationyour hardrive

Posted 04 March 2013 - 11:32 AM

how do you get a table like:
letters = {"a", "b", "c"}
to
"abc"

#2 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 04 March 2013 - 11:35 AM

local output = ""
local mytable = {"a", "b", "c"}

for i = 1, #mytable do output = output .. mytable[i] end

print(output)

You want me to explain?

#3 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 04 March 2013 - 11:36 AM

Nicer way:

str = table.concat(letters)
print(str)

Only works with tables with numeric indices though.

#4 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 04 March 2013 - 11:37 AM

Now that's why YOU are the "Lua God" and I am the "Scripter" :D

#5 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 04 March 2013 - 11:40 AM

usage is table.concat("string","spacer")
spacer can be anything separating the table elements (including nil or "")

#6 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 04 March 2013 - 11:44 AM

View PostPixelToast, on 04 March 2013 - 11:40 AM, said:

-snip-
I know what table.concat is, I just have no experience with it yet. That's why I haven't mentioned it...

(I know that that post was mainly an answer for ETHANATOR - or at least I hope so...)





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users