Extra notes for processing Javascript Chinese strings

Source: Internet
Author: User

The character constants in javascript files are closely related to the character encoding in the js file. See the following code:

Var strSex = "male ";

In GB2312 encoding, assume that another variable, strAxSex, is the BSTR value read from the ActiveX control, and the original value is also "male". In this case, compare it in javascript: strSex = strAxSex is false, that is, "male "! = "Male ".

However, if the expression strSex = strAxSex is true in VS2005 debugging, view strSex in detail. charCodeAt (0) and strAxSex. charCodeAt (0) is equal, while strSex. charCodeAt (0) and strAxSex. charCodeAt (0) is also NaN.

Pay attention to the vs2005 variable value prompt and you can see strSex = "□□". It turns out that the character constant is not unicode, so strSex is assigned a value different from the unicode Value of "male. Try to save the js file as UTF-8 encoded and run it again. Finally, strSex = strAxSex is true. The program runs the same way as the debugger, and is consistent with the daily logic.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.