Obtaining a Character value from a Unicode (numeric) value

D

david

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.
 
G

Gordon Beaton

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
 
T

Thomas Fritsch

david said:
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.
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
 
J

John C. Bollinger

david said:
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
(e-mail address removed)
 
Joined
Sep 26, 2007
Messages
1
Reaction score
0
david said:
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

You can use
char c = '\u00f7';

Harun
 
Joined
Oct 10, 2012
Messages
1
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top