Advertisement
Guest User

Untitled

a guest
Jan 5th, 2014
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1.     public String getUnicodeConversion(String input) {
  2.         int slot = 0;
  3.         int end = 0;
  4.         while(slot != -1) {
  5.             slot = input.indexOf("\\u", end);
  6.             if(slot != -1) {
  7.                 end = input.indexOf("\\", slot + 1);
  8.                 String unicode = input.substring(slot + 2, end);
  9.                 int code = Integer.parseInt(unicode, this.HEXADECIMAL);
  10.                 byte[] bytes = intToByteArray(code);
  11.                 System.out.println("Before: " + input);
  12.                 try {
  13.                     input = input.replace("\\u" + unicode + "\\", new String(bytes, "UTF-8"));
  14.                     System.out.println("After: " + new String(bytes, "UTF-8"));
  15.                 }catch(UnsupportedEncodingException e) {
  16.                     e.printStackTrace();
  17.                     return "Unsupported Encoding Text";
  18.                 }
  19.             }
  20.             break;
  21.         }
  22.         return input;
  23.     }
  24.    
  25.     public final byte[] intToByteArray(int value) {
  26.         return new byte[] {
  27.                 (byte) (value >>> 24),
  28.                 (byte) (value >>> 16),
  29.                 (byte) (value >>> 8),
  30.                 (byte) (value)
  31.         };
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement