General discussion about LÖVE, Lua, game development, puns, and unicorns.
-
BenCharles
- Prole
- Posts: 2
- Joined: Mon Feb 17, 2014 6:11 am
Post
by BenCharles »
Hello,
Could someone please show me how to determine if the content of a one-character string is a letter and not a number?
Thank you

-
micha
- Inner party member
- Posts: 1083
- Joined: Wed Sep 26, 2012 5:13 pm
Post
by micha »
Try this:
Code: Select all
if tonumber(string) then
-- string is a number
else
-- string is something else
end
It works for multi-character strings, too.
-
BenCharles
- Prole
- Posts: 2
- Joined: Mon Feb 17, 2014 6:11 am
Post
by BenCharles »
Thank you that is excellent. Although it only works for identifying numbers, not letters, it's all I needed
-
Xgoff
- Party member
- Posts: 211
- Joined: Fri Nov 19, 2010 4:20 am
Post
by Xgoff »
Code: Select all
if your_string:match("%a") then
-- ...
end
Users browsing this forum: No registered users and 10 guests