Obtaining a Character value from a Unicode (numeric) value

Discussion in 'Java' started by david, Dec 10, 2003.

  1. david

    david Guest

    Hello everybody,
    In the class "Character", the method "getNumericValue(char ch)"
    helps me to obtain the Unicode numeric value of "ch".

    I would like to know which class and method need to be used in
    order to obtain the inverse of "getNumericValue(char ch)", that is,
    from a Unicode numeric value obtain the equivalent Character value.
    Please.

    Thanking you in advance for your response.

    --
    David.H
    david, Dec 10, 2003
    #1
    1. Advertising

  2. On Wed, 10 Dec 2003 07:15:11 +0400, david wrote:
    > In the class "Character", the method "getNumericValue(char ch)"
    > helps me to obtain the Unicode numeric value of "ch".
    >
    > I would like to know which class and method need to be used in
    > order to obtain the inverse of "getNumericValue(char ch)", that is,
    > from a Unicode numeric value obtain the equivalent Character value.


    There is no such function. Although each character has (at most) one
    numeric value, each value could potentially map to many different
    characters. For example, how should the function know which of the 51
    characters to return for the value 1?

    See:
    http://www.unicode.org/Public/UNIDATA/extracted/DerivedNumericValues.txt

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Dec 10, 2003
    #2
    1. Advertising

  3. david wrote:

    >Hello everybody,
    >In the class "Character", the method "getNumericValue(char ch)"
    >helps me to obtain the Unicode numeric value of "ch".
    >
    >I would like to know which class and method need to be used in
    >order to obtain the inverse of "getNumericValue(char ch)", that is,
    >from a Unicode numeric value obtain the equivalent Character value.
    >Please.
    >
    >Thanking you in advance for your response.
    >
    >--
    >David.H
    >
    >
    >

    See the docu of the Character class! Character.forDigit is roughly the
    inverse of Character.getNumericalValue.
    Example:
    Character.forDigit(2, 10) == '2'
    Character.getNumericalValue('2') == 2

    Thomas
    Thomas Fritsch, Dec 10, 2003
    #3
  4. david wrote:

    > Hello everybody,
    > In the class "Character", the method "getNumericValue(char ch)"
    > helps me to obtain the Unicode numeric value of "ch".


    The way you phrased that and the followup question lead me to wonder
    whether Character.getNumericValue(char) is doing what you think it's
    doing. In particular, Unicode is only peripherally relevant to the
    matter -- if Java internally used Latin-1 or even ASCII for chars
    instead of Unicode, then Character.getNumericValue('1') would still
    return the exact same value: 1. See the API docs for the full method
    description.

    If what you are really looking for is, as it sounds to me, conversion
    between chars and int indices into the Unicode code table then you're
    missing the forest for the trees: a char is already such an index.

    > I would like to know which class and method need to be used in
    > order to obtain the inverse of "getNumericValue(char ch)", that is,
    > from a Unicode numeric value obtain the equivalent Character value.


    If you're asking what I think you're asking, then "Character ch = new
    Character(myChar);" ought to do what you want. Or if you mean the char
    value rather than the Character value, then "char c = (char) myInt;"
    would be the thing.


    John Bollinger
    John C. Bollinger, Dec 10, 2003
    #4
  5. Did you try converting an int ot char ? Just an idea ..
    Goldin Evgeny, Dec 10, 2003
    #5
  6. david

    david Guest

    Le Wed, 10 Dec 2003 10:18:39 -0500, John C. Bollinger a écrit :

    > "char c = (char) myInt;"


    Thank you all for your response, i didn't thought about casting.

    --
    David.H
    david, Dec 10, 2003
    #6
  7. david

    Harun Jug

    Joined:
    Sep 26, 2007
    Messages:
    1
    You can use
    char c = '\u00f7';

    Harun
    Harun Jug, Sep 27, 2007
    #7
  8. david

    Ricardo Dominguez

    Joined:
    Oct 10, 2012
    Messages:
    1
    Forget to manage unicode values with Character, char is only a byte, and an unicode char is represented by 2 bytes. I suggest the following solution:

    You can print all the lowercase chars with this:

    // 97 for 'a' and 123 for 'z', go beyond if u search for uppercase.
    for(int i=97;i<123;i++)
    System.out.println(String.valueOf(Character.toChars(i)));

    and you can get the numeric value of each using this:

    int numericValue = (int)new Character('a').charValue();

    in this case you will obtain numericValue = 97
    Ricardo Dominguez, Oct 10, 2012
    #8
    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. Kenneth McDonald
    Replies:
    1
    Views:
    809
    Carl Banks
    Dec 27, 2006
  2. Replies:
    5
    Views:
    909
    X-Centric
    Jun 30, 2005
  3. darrel
    Replies:
    4
    Views:
    786
    darrel
    Jul 19, 2007
  4. William Heymann
    Replies:
    5
    Views:
    582
    Ben Finney
    Feb 18, 2008
  5. Tyler
    Replies:
    1
    Views:
    923
    Robert Klemme
    Jul 29, 2011
Loading...

Share This Page