105 posts
Posted 06 November 2013 - 08:01 AM
So i want to be able to receive a string, and then split it apart and place it in a table. I want to use it so that I could design some encryption software, so i want something like this:
print() --line of code I want to encrypt
table = {"p","r","i","n","t","(",")"} --resulting table
570 posts
Location
Germany
Posted 06 November 2013 - 09:24 AM
You could use this:
local letters = {}
for i = 1, s:len() do
table.insert(letters, s:sub(i, i))
end
The string you want to split would be s and the output table would be letters
105 posts
Posted 06 November 2013 - 04:43 PM
You could use this:
local letters = {}
for i = 1, s:len() do
table.insert(letters, s:sub(i, i))
end
The string you want to split would be s and the output table would be letters
Thanks! But how would I add the 'print' function?
7083 posts
Location
Tasmania (AU)
Posted 07 November 2013 - 02:32 AM
KoN's code dumps whatever you put in the string "s" into the table. Hence if you wanted to put the text "print()" in there, you'd execute s = "print()" before the rest of his example.