hi i've been sent by shawn to shawn to tell shawn that it works
but i gotta make it look cool and legit by doing an explanation
First let's have a set string, what about
ye h1 th3r3
It has 6 letters and 3 numbers, but how do we make the script recognize what the letters are?
ez pz help i forgot how to write answers
local str = "ye h1 th3r3"
local alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Using a vry cool variable named "alphabet", which represents the alphabet, this is also our script's way of figuring out what is a letter and what is not.
cool, now what?
are we just going to loop and hope for the best?
nah, instead, we'll use string.gsub, which returns 2 values which will come in handy for our purposes.
String.gsub(s, n, j) returns 2 values:
A copy of s, with all n replaced by j
and
how many matches it detetctesd
We can use the second value
local str = "ye h1 th3r3"
function findLtrs(str)
local alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
local count = 0
for i = 1,#alphabet do
local h, c = str:gsub(alphabet:sub(i,i), "")
count = count + c
end
return count
end
4 comments
Is it going to be only numbers in there with letters or symbols too?
@LegitimatlyMe Hmm. Symbols will be in there too most likely
Why not just remove the symbols and numbers and do #str?
@LegitimatlyMe I could remove the symbols, but I need the numbers in there. I'm looking to see if the amount of numbers in the string + the amount of letters in string = length of string. That'll basically tell me that left overs are symbols.