Is it possible to detect if the first 'letter' somebody said was a letter or something else like a 9 or a :?
✓ ANSWER ACCEPTED
How to detect if somebody used a letter or not?
1 answer
✓ Accepted answer
Yes, you can use the string.sub function to slice strings in order to compare parts of them.
msg = ":m hello"
if msg:sub(1, 1) == ":" then
print(msg:sub(2))
--^ prints "m hello"
end
Edit: Checking if a string is a letter
function is_letter(s)
if not s:match("[^%a]") then
return true
end
end
print(is_letter(msg:sub(1, 1)) and "It's a letter" or "Not a letter!")
--> Not a letter!
print(is_letter("a") and "It's a letter!" or "Not a letter!")
--> It's a letter!
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
But how do you detect if its any letter at all and without using 26 lines?
print(msg:sub(1, 1)) --> :
But how do I do it without doing if msg:sub(1,1)=="LETTER" then 26 times to make sure its a letter?
I've updated the answer