determining the nature of one character

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
BenCharles
Prole
Posts: 2
Joined: Mon Feb 17, 2014 6:11 am

determining the nature of one character

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 :)
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: determining the nature of one character

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

Re: determining the nature of one character

Post by BenCharles »

Thank you that is excellent. Although it only works for identifying numbers, not letters, it's all I needed
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: determining the nature of one character

Post by Xgoff »

Code: Select all

if your_string:match("%a") then
    -- ...
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 3 guests