generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Checking if Something is a Number or Letter

Previous Thread :: Next Thread 
ChaosStar95 is not online. ChaosStar95
Joined: 19 Feb 2009
Total Posts: 5943
19 Aug 2011 03:44 PM
Don't be confused; this is not about strings vs numbers, this is letters vs numbers. Say the Text property of a TextLabel was "123ABC456". Now obviously there are six numbers and three letters in that string, but I need to know how to tell if there are any letters in it by using a script.
Here's why I need to do this: I've made an InsertService plugin where you can type in an ID and click a location so the script inserts the said object at that location. Now, whenever letters are typed in, the plugin breaks.
Therefore, I need to know how to do this just so no one accidently types in a letter and breaks the plugin and has to reload Roblox Studio to get it to work again.
Report Abuse
myrco919 is not online. myrco919
Joined: 12 Jun 2009
Total Posts: 13241
19 Aug 2011 03:47 PM
[ Content Deleted ]
Report Abuse
ChaosStar95 is not online. ChaosStar95
Joined: 19 Feb 2009
Total Posts: 5943
19 Aug 2011 03:54 PM
@myrco:
I'm talking about checking if it's a number or a letter.
I tried:
print(type("123"))
Output said it was a string.
Remember, I'm asking about checking if the characters in a string are either letters or numbers, not strings or numbers.
Report Abuse
chikenugget is not online. chikenugget
Joined: 09 May 2009
Total Posts: 2552
19 Aug 2011 03:58 PM
Inefficient, but I personally dont care

asset =
num = {}

for i = 1,10 do
table.insert(num,i)
end
for x = 1,asset:len() do
for y = #num do
if asset:sub(x,x) ~= num[y] then
print'not a number?'
end
end
end



~~ In Soviet Russia, scripts write you. ~~
Report Abuse
ChaosStar95 is not online. ChaosStar95
Joined: 19 Feb 2009
Total Posts: 5943
19 Aug 2011 04:04 PM
Wow, I found a remarkably easy way to do it:

x = "123"
if tonumber(x) then
print(tonumber(x))
end

Add letters into x and it does nothing. Keep it as numbers and it prints x.
Report Abuse
chikenugget is not online. chikenugget
Joined: 09 May 2009
Total Posts: 2552
19 Aug 2011 04:05 PM
I feel so useless. T_T

~~ In Soviet Russia, scripts write you. ~~
Report Abuse
ChaosStar95 is not online. ChaosStar95
Joined: 19 Feb 2009
Total Posts: 5943
19 Aug 2011 04:06 PM
Thanks for your help anyways though, guys. I appreciate it.
Report Abuse
myrco919 is not online. myrco919
Joined: 12 Jun 2009
Total Posts: 13241
19 Aug 2011 04:07 PM
[ Content Deleted ]
Report Abuse
DigitalRunner is not online. DigitalRunner
Joined: 07 Aug 2011
Total Posts: 193
19 Aug 2011 04:08 PM
Couldn't you use a string pattern?
Report Abuse
ChaosStar95 is not online. ChaosStar95
Joined: 19 Feb 2009
Total Posts: 5943
19 Aug 2011 04:17 PM
@myrco:
print(type("5")) > string
I want that to return number, understand now?
That's why I couldn't use your way.
Report Abuse
myrco919 is not online. myrco919
Joined: 12 Jun 2009
Total Posts: 13241
19 Aug 2011 04:23 PM
[ Content Deleted ]
Report Abuse
ChaosStar95 is not online. ChaosStar95
Joined: 19 Feb 2009
Total Posts: 5943
19 Aug 2011 04:29 PM
I know. I don't care if it's a string, so I can't use type(). I'm talking about if it's either a multiple of 1 or in the alphabet, not if it has quotation marks around it.
What I'm doing is actually all in strings:
"12345"
"ABCDE"
Those are both strings. But one is composed of numbers and one is composed of letters. That's what I needed help with.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image