| 07-19-2009, 01:17 AM | #1 |
JASS:function IsStringNumeric takes string s returns boolean if s == "" or s == null then return false elseif S2I(s) != 0 then return true endif return S2I(s + "1") != 0 endfunction I just came up with this simple function, which detects whether the string is S2I compatible. Pros:
Cons:
Any other suggestions or ideas? |
| 07-19-2009, 01:44 AM | #2 |
Wouldn't this do the same? JASS:function IsStringNumeric takes string s returns boolean return S2I(s)!=0 or s=="0" endfunction |
| 07-19-2009, 02:14 AM | #3 | |
Quote:
What if s is "00", "+0", "-0", etc.? Thinking of it: Isn't there a maximum string length? At least for S2I? If so, the original poster's function would fail if the string consisted of maximum string length number of zeros ;) |
| 07-19-2009, 02:17 AM | #4 | |
Quote:
I just realized: The function would return true if the string were "+" or "-". Is this intended? |
| 07-19-2009, 06:39 AM | #5 | |
Quote:
Oh, I didn't realize that. Thanks for letting me know. Added: blank spaces seem to mess up if I add checks for + or -... lol... also S2I(" 10 asdf 19") is 10; means " 00 " will return false :( |
| 07-19-2009, 07:36 AM | #6 |
function IsStringNumeric takes string s returns boolean return I2S(S2I(s)) == s endfunction |
