View Full Version : charCodeAt Help Required

01-26-2006, 09:34 AM
I am trying to write a conversion program using charCodeAt and fromCharCode but can't understand why the numbers are bigger than 256:

alert("".charCodeAt(0)); ===> gives 382
alert("".charCodeAt(0)); ===> gives 8221

Is there anything that I must set to make this be under 256


01-26-2006, 09:39 AM
The numbers are bigger than 256 because the Unicode code points for those characters are above 256.

01-26-2006, 10:03 AM

Thanks for the quick response.

I am just wondering why in VB this works out to be:


01-26-2006, 10:24 AM
Because those are the mappings for the Windows-1252 (http://en.wikipedia.org/wiki/Windows-1252) code page (http://www.microsoft.com/globaldev/reference/sbcs/1252.mspx). But browsers use Unicode internally, and also the ECMAScript standard specify Unicode as the the character set used.

02-14-2006, 05:40 AM
Thanks for all the tips. I have bypassed the problem by mapping it with the standard character set.

BTW, is there any Javascript routine or documentation for converting Text Encodings like GB2312 etc into pure unicode? Can't seem to find any postings in this forum

Thanking you in advance!

02-14-2006, 10:00 AM
No. JavaScript is supposed to always work on Unicode (at least internally) so there shouldn't be any need at all for that kind of facility. However, sometimes browsers don't quite keep track of character encodings as well as they should...