I wanted to make a word shifter for roblox, since my friend gave me the idea.. The thing is, I don't know how I can change the specific string to another when the button "Encode" is clicked.
I want the string to be change to the next alphabet for example
if they type abc in the textbox when they click encode, it will be bcd
word shifter will shift the alphabet to another which means a=b b=c c=d e=f
and so on Please help me!! I know its super simple to you awesome programmers!!! So Please Help Me Out..
it really is quite simple, you just use string.gsub()
!
read more here: strings
code:
local Alphabet = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r","s","t", "u", "v", "w", "x", "y", "z"} -- just incase you wanna do it easier for decode and encode. local Encode = {} local Decode = {} local function CreateEncode(One, Two) Encode[#Encode + 1] = {O = One, T = Two} end local function CreateDecode(One, Two) Decode[#Decode + 1] = {O = One, T = Two} end local function EncodeString(String) local Temp = {} for i = 1,#Encode do local Split = string.sub(String, i, i) Split = string.gsub(Split, Encode[i].O, Encode[i].T) table.insert(Temp, Split) end return table.concat(Temp, "") end local function DecodeString(String) local Temp = {} for i = 1,#Decode do local Split = string.sub(String, i, i) Split = string.gsub(Split, Decode[i].O, Decode[i].T) table.insert(Temp, Split) end return table.concat(Temp, "") end CreateEncode("a", "b") CreateEncode("b", "c") CreateEncode("c", "d") CreateDecode("b", "a") CreateDecode("c", "b") CreateDecode("d", "c") print(EncodeString("abc")) print(DecodeString("bcd"))