Darwinbots Forum
Code center => Darwinbots Program Source Code => Topic started by: Zelos 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?
-
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.
-
I think val(string) would return 0 if the string isn't a number, if that's helpful...
-
"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.
IsNumeric("hello") = False
IsNumeric("77") = True
IsNumeric("hello77") = False
IsNumeric("77.55") = True
IsNumeric("1,099") = True
-
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. :(
-
"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.
-
"val(string)" will return 0 if the argument isn't a number.
-
"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:
-
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?
-
quite possibly. I don't tend to use "val" very much as the output format is limited.