File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to get unicode for a character? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get unicode for a character?" Watch "How to get unicode for a character?" New topic
Author

How to get unicode for a character?

Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Hi,

May be this looks like a simple problem. But I could not get the right hook to get the solution. All I want is to get unicode for a character.
We can get unicode format for a input file on the command prompt using
native2ascii -encoding [encoding name] [inputfile] [outputfile].

But I want a method to convert a character to unicode or a string to unicode. Can someone show some light on this?

Thanks and Regards,
Narendranath


Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

A Java char is a Unicode value, so I'm not clear what you're asking. Do you want to make a String that looks like "\uXXXX" from a char value? You could use the java.text.NumberFormat class to do that easily enough.


[Jess in Action][AskingGoodQuestions]
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

I just want a character to be converted to unicode.

i,e.. if I have something like this

char c='A';
At runtime I want the unicode value of 'A'. For that I any method which converts character to unicode.

Regards,
Narendranath
Mahesh x Bogadi
Ranch Hand

Joined: Jul 06, 2004
Posts: 51
char c = 'A';

System.out.println(Integer.parseIt((int)c, 16); //in Hexa

This will print the unicode value
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Quote:char c = 'A';
System.out.println(Integer.parseIt((int)c, 16); //in Hexa


Whatever you have written doesn't work. Better check before posting.
Moreover, even if it works by modifying some how I want character in unicode as output not even string like "\u0045".
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
final int i = c; // that wasn't hard now was it?


Tony Morris
Java Q&A (FAQ, Trivia)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get unicode for a character?