2

How can I convert this string: This string contains the unicode character unicodetoString("\u0064") and string to unicode like stringtounicode("a")?

public static String GetUnicode(String str_code) {          
String hexCode = Integer.toHexString(str_code.codePointAt(0)).toUpperCase();        
    String hexCodeWithAllLeadingZeros = "0000" + hexCode;
    String hexCodeWithLeadingZeros = hexCodeWithAllLeadingZeros
    .substring(hexCodeWithAllLeadingZeros.length() - 4);
    hexCodeWithLeadingZeros = "\\u" + hexCodeWithLeadingZeros;
    System.out.println("Unicode " + hexCodeWithLeadingZeros);
    return hexCodeWithLeadingZeros;
}    
8
  • Strings have an encoding, which may be unicode or something else. "Unicode to String" implies that either unicode is a data type like string is, or that string is a character encoding like unicode is. As it stands, your question is nonsensical. (It might help to know that java strings internally use utf-16. Is that what you mean?) Commented Sep 12, 2012 at 8:58
  • 1
    public static String GetUnicode(String str_code) { // TODO Auto-generated method stub //StringBuilder hexcode = Integer.toHexString(str_code.codePointAt(0)).toUpperCase(); String hexCode = Integer.toHexString(str_code.codePointAt(0)).toUpperCase(); String hexCodeWithAllLeadingZeros = "0000" + hexCode; String hexCodeWithLeadingZeros = hexCodeWithAllLeadingZeros .substring(hexCodeWithAllLeadingZeros.length() - 4); String myunicode = "\\u" + hexCodeWithLeadingZeros; // System.out.println("\\u" + hexCodeWithLeadingZeros); return myunicode; } Commented Sep 12, 2012 at 9:03
  • 1
    String is a stream of characters. Each character is represented by unique number, called unicode. Methods for converting this number to binary is called encoding. Commented Sep 12, 2012 at 9:04
  • 1
    so you are not converting a string to unicode, unicode is a way to represent character. saying converting string to unicode makes no sense. Commented Sep 12, 2012 at 9:06
  • 2
    @umarmansuri Please add that code to your original question. It is not readable in the comments. Commented Sep 12, 2012 at 9:35

1 Answer 1

1

To Convert a unicode to string use

StringEscapeUtils.unescapeJava(unicodeString)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.