This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
austinv11's profile picture

How Do I Separate Letters From Any Given String?

Started by austinv11, 06 November 2013 - 07:01 AM
austinv11 #1
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
M4sh3dP0t4t03 #2
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
austinv11 #3
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?
Bomb Bloke #4
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.