Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String to char.

 
Atrus Greyor
Ranch Hand
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would I convert a string that has the value of "\u0020" (as an example) into a char?

Thanks for the help.
 
Samuel Behrman
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the String.charAt(index) method.
If there's just one character in the String, just use charAt(0).
 
Atrus Greyor
Ranch Hand
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't. I want to turn the Unicode value into a single char.

So, the string with the value of "\u0020" should be the char of ' ' (space).
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If somebody has already posted the correct answer, please read it.
 
Atrus Greyor
Ranch Hand
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Huh? I don't want to get an individual char from a string.

For example, if I have a JTextField and a JLabel. The user literally types in the JTextField "\u004D", the JLabel should display an 'M'.

However, I figured it out. Just take the last four characters of the string (running under the assumption that it is a valid Unicode number), and put it through Integer.parseInt(string, 16); Cast that result to a char, and done.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic