Answered
I've got a simple script that pulls the first two chars from a string (as part of a date calculation).
Substr seems to work fine on any string starting with anything other than 08 or 09, but returns zero when the string starts with 08 or 09.
var res;
var str;
str = '07';
res = parseInt(str.substr(0,2));
xfa.host.messageBox("Result is: " + res); // this prints '07'
str = '08';
res = parseInt(str.substr(0,2));
xfa.host.messageBox("Result is: " + res); // this prints '0'
Any ideas?
Thanks.
If you want to pull numeric character strings as characters and not number, I would only use the 'substr' method and not use the 'parseInt' method. 'it' assumes the output is a number. I would also provide the radix parameter so the default of the Octal number base is not assumed when a value starts with '0' or no radix is provided. You can also use the 'typeof' operator to test for or see what the type of data you are dealing with.
You could try using the strings ,08', '09','10', an '11' and observe what happens and try to figure out why some numbers work but others do not.
George Kaiser