Converting special characters in Java and JavaScript

Discussion in 'Java' started by Crazy Monkey, Jan 21, 2005.

  1. Crazy Monkey

    Crazy Monkey Guest

    Hi:

    I need to convert special characters into its numerical values. I
    found charCodeAt() function in JavaScript that does the trick. For
    example

    var testString = "èû";
    testString.charCodeAt(0) will return 138
    testString.charCodeAt(1) will return 150


    I need something in Java that will do the same thing. So far the
    closest thing I got is

    char char1 = 'è';
    int ci = (int) char1; gives me 232

    char char1 = 'û';
    int ci = (int) char1; gives me 251


    As you see, the conversion does not match. The Java part is giving me
    a HTML encoded representation. JavaScript charCodeAt() is doing
    something else. I need Java to generate the same code as JavaScript.
    Any hints.

    Thanks.



    Crazy Monkey
    Crazy Monkey, Jan 21, 2005
    #1
    1. Advertising

  2. Crazy Monkey

    Crazy Monkey Guest

    My mistake. They actually do convert to the same number.
    Crazy Monkey, Jan 21, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Mueller
    Replies:
    3
    Views:
    33,001
    Stefan Mueller
    Jul 23, 2006
  2. Replies:
    2
    Views:
    1,089
    Ingo Menger
    May 31, 2007
  3. rvino
    Replies:
    0
    Views:
    4,651
    rvino
    Aug 14, 2007
  4. Doc

    Javascript and special characters

    Doc, Mar 27, 2006, in forum: Javascript
    Replies:
    5
    Views:
    202
    Thomas 'PointedEars' Lahn
    Mar 29, 2006
  5. majna
    Replies:
    4
    Views:
    663
    Thomas 'PointedEars' Lahn
    Sep 19, 2007
Loading...

Share This Page