okay. I am making an encryption software for a test in my skills, and I came across a problem. see, I need it to be all numbers, so I created an alphabet-to-number thing. it worked fine, but encrypting scripts with copy and paste, well, had some enters in it. (the key on the keyboard.) the problem is if var == " "won't work, so what do I do?
I think you can use a function string.find
. Basically, this returns a value that matches the string pattern you are trying to find. For example, if you are trying to find the space in the string "Hello World", you would do:
local value = "Hello World" local characterNumOfSpace = string.find(value, "%s") --%s is a string pattern of blank : " ". print(characterNumOfSpace)
This will return the value of nth character in the string, which is a " " (space).
But perhaps it would be easier if you replace replace the space with some rarly used character or string such as "PPP" Instead of directly finding the space. For example, you can do
local encodingValue = "Hello World" local replacingValue = "PPP"--I don't think anyone would type PPP in the text. If someone does, that would be replaced by space :( Maybe think of better replacing value? local encodedValue = string.gsub(encodingValue, "%s", replacingValue) print(encodedValue) --Replace the PPP with normal space local decodedValue = string.gsub(encodedValue, replacingValue," ")--Replaces the PPP to Space(" "). print(decodedValue)
This will allow you to encode the string after replacing the space to "PPP". When decoded, it will return "HelloPPPWorld", so just use string.gsub
to replace "PPP" with " ".