Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    charCodeAt Help Required

    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

    Thanks

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    The numbers are bigger than 256 because the Unicode code points for those characters are above 256.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    New to the CF scene
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    liorean,

    Thanks for the quick response.

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

    158 ×
    148 ö

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Because those are the mappings for the Windows-1252 code page. But browsers use Unicode internally, and also the ECMAScript standard specify Unicode as the the character set used.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    New to the CF scene
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #6
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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...
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •