Author Topic: String Integer Check  (Read 5235 times)

Offline Zelos

  • Bot Overlord
  • ****
  • Posts: 707
    • View Profile
String Integer Check
« on: November 10, 2005, 01:50:26 PM »
Is there a way to check if a string is a integer like if I have a string called stringa and then if it has the value "hi" or "<%" its gives false or something and if it has "5" it returns true?
When I have the eclipse cannon under my control there is nothing that can stop me from ruling the world. And I wont stop there. I will never stop conquering worlds through the universe. All the worlds in the universe will belong to me. All the species in on them will be my slaves. THE ENIRE UNIVERSE WILL BELONG TO ME AND EVERYTHING IN IT :evil: AND THERE IS NOTHING ANYONE OF you CAN DO TO STOP ME. HAHAHAHAHAHAHAHA

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
String Integer Check
« Reply #1 on: November 10, 2005, 03:01:23 PM »
no easy way that I know of.

You would have to create a function that seperates all the numbers from the other characters, then if the number of "other" characters is greater than 0 then return false.
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
String Integer Check
« Reply #2 on: November 10, 2005, 04:10:44 PM »
I think val(string) would return 0 if the string isn't a number, if that's helpful...

Offline Ulciscor

  • Bot Destroyer
  • ***
  • Posts: 401
    • View Profile
String Integer Check
« Reply #3 on: November 10, 2005, 09:29:30 PM »
"IsNumeric" will return true if the argument can be expressed as an integer and false if it can't...
... but it allows commas and periods in the argument.

Code: [Select]
IsNumeric("hello") = False
IsNumeric("77") = True
IsNumeric("hello77") = False
IsNumeric("77.55") = True
IsNumeric("1,099") = True
« Last Edit: November 10, 2005, 09:30:23 PM by Ulciscor »
:D Ulciscor :D

I used to be indecisive, but now I'm not so sure.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
String Integer Check
« Reply #4 on: November 11, 2005, 09:42:32 AM »
Quote
I think val(string) would return 0 if the string isn't a number, if that's helpful...
In my experience, val(string) crashes if the string isn't a number.  :(
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
String Integer Check
« Reply #5 on: November 11, 2005, 09:43:18 AM »
Quote
"IsNumeric" will return true if the argument can be expressed as an integer and false if it can't...
Didn't know there was such a function. Thanks for the info Ulc.
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Ulciscor

  • Bot Destroyer
  • ***
  • Posts: 401
    • View Profile
String Integer Check
« Reply #6 on: November 11, 2005, 12:09:36 PM »
"val(string)" will return 0 if the argument isn't a number.
« Last Edit: November 11, 2005, 12:22:29 PM by Ulciscor »
:D Ulciscor :D

I used to be indecisive, but now I'm not so sure.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
String Integer Check
« Reply #7 on: November 11, 2005, 12:20:59 PM »
Quote
"val(string)" will return 0 if the argument isnt a number.

Just tested it and you are right. It does return 0.

Must have been thinking about VB for Applications.

No apparently not. Just tested that too and it returns 0

Could have sworn I had seen crashes in this kind of code.  :blink:

Maybe I am just going senile.  :wacko:
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Ulciscor

  • Bot Destroyer
  • ***
  • Posts: 401
    • View Profile
String Integer Check
« Reply #8 on: November 11, 2005, 12:22:15 PM »
Lol :D

I had a go at using "CInt(string)" on non-numerical strings and that indeed crashes as you might expect... was this what you were thinking of?
:D Ulciscor :D

I used to be indecisive, but now I'm not so sure.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
String Integer Check
« Reply #9 on: November 11, 2005, 12:55:56 PM »
quite possibly. I don't tend to use "val" very much as the output format is limited.
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D