Lua convert table to string

Viewed 285

I cannot find the correct solution or I get an error for something that is very simple in C: how can I convert/move data from a table to string?

The C equivalent of what I am trying to do is:

for (i=0; i <10; i++)
{
    string[i] = table[i]
}

I can convert from string to table with :byte(i) but I don't understand how to append a sign in string.

1 Answers

To create a string from all values in a table you can use table.concat, this will concatenate each character in a table.

local myTable = { "h", "e", "l", "l", "o" }
local combinedString = table.concat(myTable)
print(combinedString) -- Outputs hello

Run Code Demo

Related