Check if is string

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
master121
Posts: 45
Joined: Mon Dec 29, 2008 10:40 am

Check if is string

#1 Post by master121 » Fri Sep 04, 2009 6:49 am

How can i check if a variable is a string or a number etc ?

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: Check if is string

#2 Post by Administrator » Fri Sep 04, 2009 7:46 am

Code: Select all

if( type(variable) == "number" ) then
  -- it's a string
elseif( type(variable) == "string" ) then
 -- it's a number
end
However, be aware that in some cases, strings can be numbers and numbers can be strings. That is, "123", "1AC", "0.123" are all strings but can be used as numbers (use tonumber() or tostring() to convert).

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 37 guests