简体   繁体   中英

Javascript Non UTF-8 Character Searching for Google Chrome Extension

Edit:

I am creating a Chrome Extension and the files must be UTF-8 encoded. I use JQuery to get contents from page, and check that if that contains specific strings that contains Ö, ı and İ. However, because the Chrome forces files must be encoded UTF-8; I cannot perform a search of "İ, ı, Ö".

var p = txt.indexOf("İ"); 

Does not work as I need because I cannot save the files with İ, Ö or ı.

JavaScript string literals include a syntax for expressing special characters .

For instance, 'Ö' and '\Ö' are identical strings in JavaScript.

To find the unicode literal for a specific character, you can do this:

'Ö'.charCodeAt(0).toString(16); // yields "d6"; the code is "\u00D6"

Therefore, to search for a Ö in a string, you could do:

var toSearch = "abc Ö def";
if (toSearch.indexOf('\u00D6') > -1) {
    // found!
}

If you need further help, try posting a code sample.

encodeURIComponent(your string)                               

encode it when you save the file, and encode the string before you search

http://www.w3schools.com/jsref/jsref_encodeURIComponent.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM