Jump to content




[lua] question on tables


  • You cannot reply to this topic
1 reply to this topic

#1 tom2018

  • Members
  • 135 posts

Posted 23 March 2013 - 12:15 PM

if i have a table like this
t = {"h","i"}
how do i turn that into
"hi"
?

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 23 March 2013 - 12:19 PM

Two methods.

Harder way, but with more flexibility:
local str = ''
for i=1, #t do
  str = str .. t[i]
end
print(str) --> hi

Easier way, less flexibility, but perfect for your purposes.
local str = table.concat(t)
print(str) --> hi

In the future, you can also use an optional separator with table.concat if you want.
local str = table.concat(t, ',')
print(str) --> h,i






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users