Reputation: 12581
Please note that this question is not a duplicate.
I have a String like this:
// My String
String myString = "U+1F600";
// A method to convert the String to a real character
String unicodeCharacter = convertStringToUnicode(myString);
// Then this should print: 😀
System.out.println(unicodeCharacter);
How can I convert this String to the unicode character 😀
? I then want to show this in a TextView
.
Upvotes: 3
Views: 3150
Reputation: 48297
What you are trying to do is to print the unicode when you know the code but as String... the normal way to do this is using the method
like:
System.out.print(Character.toChars(0x1f600));
now in you case, you have
String myString = "U+1F600";
so you can truncate the string removing the 1st 2 chars, and then parsing the rest as an integer with the method Integer.parseInt(valAsString, radix)
String myString = "U+1F600";
System.out.print(Character.toChars(Integer.parseInt(myString.substring(2), 16)));
Upvotes: 7