I have the following code:
var item = myFoundItems[i].contents; //this is some text in Arabic, followed by an Arabic number. But the type is String. eg. "Page 15"
var pageNumber = item.slice(7); //the page number itself
convPageNumber = Number(pageNumber); //change the string into a number
Now, after the last line, the value of convPageNumber is NaN. I think the problem is that the Arabic number is somehow not recognized...
What can I do?
Thanks,
Ola
pageNumber.charCodeAt(0);
in the JavaScript Console to see what character is actually there where the "1" appears to be.
Dave
Now what number do you get when you inspect the character code? If the used font was a 'hack' one, you will get the code for a '1' (U+0030). But since the Number function relies on that code, and it apparently fails, I'm betting you get the code for a '١' -- the Arabic '1', U+0661.
If you need to convert the string to a real number, inspect the string one charcode at a time, making no assumptions about the coding. If its code is inbetween 48 and 57 (inclusive), it's a roman digit; subtract 48 from it to get the numerical value. If it is between 1632 and 1641 (the decimal value of the hex-based U+ codes), simply subtract 1632 to get this numerical value. Any other values could be considered 'end-of-number' -- or, well, except if you have used 'extended Arabic' (U+6F0..U+6F9), 'Devanagari' (U+0966..U+096F), 'Bengali', or any other script system digits as well.
Reconstructing the entire number from these is basic math.
What I actually did in the end to solve that was pretty primitve:
I put in the script Find/Replace commands to search for all 10 arabic digits and replace them with the regular digits. This solved the problem...
Ola