|
| 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
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 19 Aug 2011 04:05 PM |
I feel so useless. T_T
~~ In Soviet Russia, scripts write you. ~~ |
|
|
| Report Abuse |
|
|
|
| 19 Aug 2011 04:06 PM |
| Thanks for your help anyways though, guys. I appreciate it. |
|
|
| Report Abuse |
|
|
myrco919
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|
|
| 19 Aug 2011 04:08 PM |
| Couldn't you use a string pattern? |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|
|
| 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 |
|
|