Search code examples
javaunicode-string

How do I convert a unicode-string to a readable string


I have this string "\U05d0\U05d5\U05d2\U05e0\U05d3\U05d4","\U05d0\U05d5\U05d6\U05d1\U05e7\U05d9\U05e1\U05d8\U05df","\U05d0\U05d5\U05e1\U05d8\U05e8\U05d9\U05d4"

how do i convert it to a readable string? (note this is supposed to be hebrew)

i tried this method but it didnt work

byte[] bytes = s.getBytes();
String decoded = new String(bytes); 
System.out.println(decoded);

Solution

  • All U should be lowercase u:

        String s = "\u05d0\u05d5\u05d2\u05e0\u05d3\u05d4";
    
        try{
    
            byte[] bytes   = s.getBytes();
            String decoded = new String(bytes); 
    
            System.out.println(decoded);
    
        } catch(UnsupportedEncodingException e) {      
            // ...  
        }
    

    See Byte Encodings and Strings.

    Output:

    אוגנדה