string to integer
Monkey Forums/Monkey Bug Reports/string to integer
| ||
This produce Invalid Integer in androidLocal str$="" Local J=Int(str[0..1]) + 3 Print J I would like the answer to be 3 instead. And I not in debug mode but the error produce statement in my release game something like this 'Monkey produce error: Invalid integer "J" ' |
| ||
This has nothing to do with type conversion. str[0..1] creates a String containing the first character of str. str is an empty string, so it fails, as expected. If you want to supply a default value, you should do something like this: [monkeycode]Local str$="" Local J%=3 If str Then J = Int(str[0..1])[/monkeycode] |
| ||
Ok sorry my sample code got involve with array. That not the issue. You got to try this code in android. 'This Error Local str$="" Local J=Int(str) Print J+3 'This no error Local J=Int("") Print J+3 'This produce error Local str$="M" Local J=Int(str) Print J+3 'This no error Local J=Int("M") Print J+3 One by one |