Jump to content




How Do I Separate Letters From Any Given String?


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

#1 austinv11

  • Members
  • 107 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


#2 M4sh3dP0t4t03

  • Members
  • 255 posts
  • LocationGermany

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

#3 austinv11

  • Members
  • 107 posts

Posted 06 November 2013 - 04:43 PM

View PostK4rt0ff3lBr31(KingOfNoobs), on 06 November 2013 - 09:24 AM, said:

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?

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users