I have a string of Arabic characters:
var txt="یہ ایک جملہ ہے۔";
And I want to find the position of a certain character (e.g. ج) in this string.
alert (txt.indexOf("ج"));
I tried using txt.indexOf() function but something really strange happens: if I specify the strings (both: the base string and the search string) in real-time (e.g. through an inputbox or form textbox) then it works as intended. However, when I specify the characters of the base string as a hard coded JavaScript line, then all hell breaks loose.
The characters appear as some bizarre ASCII values when I alert() them (appearing as Ößùīñè etc) and the indexOf result always returns -1 (not found). Initially I thought it's an issue with the js file encoding to ensure it supports the extended character set. Turns out the encoding is UTF-8 and the characters appear perfectly fine in the editor when I close and then reopen the file. The problem is only when processing them with JavaScript.
I am using notepad++ as the code editing software.
var txt="یہ ایک جملہ ہے۔";
console.log(txt.indexOf("ج"));
Any help would be greatly appreciated.