Home > Web Front-end > JS Tutorial > Additional considerations for Javascript Chinese string processing_javascript tips

Additional considerations for Javascript Chinese string processing_javascript tips

WBOY
Release: 2016-05-16 18:41:38
Original
1026 people have browsed it

var strSex="Male";

In GB2312 encoding, assume that there is another variable strAxSex which is the BSTR value read from the ActiveX control, and the original value is also "Male". At this time, do it in the javascript program Compare: strSex==strAxSex is false, that is, "male"!="male".

But if you look at the expression strSex==strAxSex from VS2005 debugging, it is true. If you look closely, strSex.charCodeAt(0) and strAxSex.charCodeAt(0) are also equal, and strSex.charCodeAt(0) is equal to strAxSex.charCodeAt(0) is also equal to NaN.

Look at the vs2005 variable value prompt again, you can see strSex="□□". It turns out that the character constant is non-unicode, causing the value assigned to strSex to be different from the unicode value of "male". Try to save the js file as encoding utf-8 and run it again. Finally strSex==strAxSex is true. The program execution is consistent with the debugger and is consistent with the daily logic.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template