最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

utf 8 - Javascript Non UTF-8 Character Searching for Google Chrome Extension - Stack Overflow

programmeradmin6浏览0评论

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 ı.

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 ı.

Share Improve this question edited Jun 4, 2011 at 18:52 Mustafa asked Jun 4, 2011 at 18:38 MustafaMustafa 10.4k12 gold badges76 silver badges122 bronze badges 3
  • UTF-8 can represent pretty much any character, as long as you have a Unicode-aware text editor. Do you mean that the files must be saved as ASCII? – Tyler Commented Jun 4, 2011 at 21:40
  • By the way, I highly remend reading this: joelonsoftware./articles/Unicode.html – Tyler Commented Jun 4, 2011 at 21:40
  • Isn't the bug that Javascript doesn't support Unicode? You should be able to write what you have written there without any trouble. – tchrist Commented Jun 5, 2011 at 18:13
Add a ment  | 

2 Answers 2

Reset to default 7

JavaScript string literals include a syntax for expressing special characters.

For instance, 'Ö' and '\u00D6' 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./jsref/jsref_encodeURIComponent.asp

发布评论

评论列表(0)

  1. 暂无评论