Code center > Darwinbots Program Source Code

String Integer Check

(1/2) > >>

Zelos:
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?

PurpleYouko:
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.

Numsgil:
I think val(string) would return 0 if the string isn't a number, if that's helpful...

Ulciscor:
"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: ---IsNumeric("hello") = False
IsNumeric("77") = True
IsNumeric("hello77") = False
IsNumeric("77.55") = True
IsNumeric("1,099") = True
--- End code ---

PurpleYouko:

--- Quote ---I think val(string) would return 0 if the string isn't a number, if that's helpful...
--- End quote ---
In my experience, val(string) crashes if the string isn't a number.  :(

Navigation

[0] Message Index

[#] Next page

Go to full version