Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Obtaining a Character value from a Unicode (numeric) value

Reply
Thread Tools

Obtaining a Character value from a Unicode (numeric) value

 
 
david
Guest
Posts: n/a
 
      12-10-2003
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

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      12-10-2003
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/UNIDAT...ericValues.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
 
Reply With Quote
 
 
 
 
Thomas Fritsch
Guest
Posts: n/a
 
      12-10-2003
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

 
Reply With Quote
 
John C. Bollinger
Guest
Posts: n/a
 
      12-10-2003
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
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
Goldin Evgeny
Guest
Posts: n/a
 
      12-10-2003
Did you try converting an int ot char ? Just an idea ..
 
Reply With Quote
 
david
Guest
Posts: n/a
 
      12-10-2003
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
 
Reply With Quote
 
Harun Jug Harun Jug is offline
Junior Member
Join Date: Sep 2007
Posts: 1
 
      09-27-2007
Quote:
Originally Posted by 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.

--
David.H
You can use
char c = '\u00f7';

Harun
 
Reply With Quote
 
Ricardo Dominguez Ricardo Dominguez is offline
Junior Member
Join Date: Oct 2012
Posts: 1
 
      10-10-2012
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.toChar s(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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Resolving unicode escapes to unicode character Tyler Ruby 1 07-29-2011 01:47 PM
Getting unicode escape sequence from unicode character? Kenneth McDonald Python 1 12-27-2006 10:27 PM
Does somebody know how to print out wild character with unicode value greater than 255 jackie C++ 2 01-07-2005 08:43 AM
Re: How do you extract hex value of a Unicode character ? John Lenton Python 0 07-15-2004 12:41 PM
Unicode value of a character JPR105 Java 3 04-25-2004 11:21 PM



Advertisments