Win a copy of Getting started with Java on the Raspberry Pi this week in the Raspberry Pi forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

How to get unicode for a character?

 
Ranch Hand
Posts: 577
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
final int i = c; // that wasn't hard now was it?
 
Been there. Done that. Went back for more. But this time, I took this tiny ad with me:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic