| Author |
String to char.
|
Atrus Greyor
Ranch Hand
Joined: Mar 07, 2004
Posts: 110
|
|
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
Joined: Oct 02, 2009
Posts: 49
|
|
You can use the String.charAt(index) method.
If there's just one character in the String, just use charAt(0).
|
RAQ Report: Web-based Excel-like Java reporting tool.
|
 |
Atrus Greyor
Ranch Hand
Joined: Mar 07, 2004
Posts: 110
|
|
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
Joined: Oct 13, 2005
Posts: 32644
|
|
|
If somebody has already posted the correct answer, please read it.
|
 |
Atrus Greyor
Ranch Hand
Joined: Mar 07, 2004
Posts: 110
|
|
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.
|
 |
 |
|
|
subject: String to char.
|
|
|