I have a method that translates a
string into a unicode string
public String unicodeEncoderAll(String str){
StringBuffer sb = new StringBuffer();
for(int i=0; i<str.length(); i++) {
char ch = str.charAt(i);
sb.append("\\u") ;
String hex = Integer.toHexString(str.charAt(i) & 0xFFFF);
for(int j=0; j><4-hex.length(); j++) {
sb.append("0");
}
sb.append(hex.toLowerCase());
}
return (new String(sb));
}
Takes a string Hello an returns \u0048\u0065\u006c\u006c\u006f
The problem is translating it back
String str = encoder.unicodeEncoderAll("Hello");
System.out.println("
Test Decoded str "+encoder.testDecoder(str));
outputs \u0048\u0065\u006c\u006c\u006f
System.out.println("Test Decoded str "+encoder.testDecoder("\u0048\u0065\u006c\u006c\u006f"));
outputs Hello
So the encoded string will not output the string Hello, but it will decode back if hardcoded in.
Cheers for any help