Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how can i do something like if var == enter?

Asked by 4 years ago

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?

1 answer

Log in to vote
1
Answered by
Yuuwa0519 197
4 years ago

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 " ".

0
the string.find works codingMASTER398 52 — 4y
Ad

Answer this question