Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get unicode for a character?

 
Naren Chivukula
Ranch Hand
Posts: 577
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Naren Chivukula
Ranch Hand
Posts: 577
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
char c = 'A';

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

This will print the unicode value
 
Naren Chivukula
Ranch Hand
Posts: 577
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
final int i = c; // that wasn't hard now was it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic