Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String getUnicodeConversion(String input) {
- int slot = 0;
- int end = 0;
- while(slot != -1) {
- slot = input.indexOf("\\u", end);
- if(slot != -1) {
- end = input.indexOf("\\", slot + 1);
- String unicode = input.substring(slot + 2, end);
- int code = Integer.parseInt(unicode, this.HEXADECIMAL);
- byte[] bytes = intToByteArray(code);
- System.out.println("Before: " + input);
- try {
- input = input.replace("\\u" + unicode + "\\", new String(bytes, "UTF-8"));
- System.out.println("After: " + new String(bytes, "UTF-8"));
- }catch(UnsupportedEncodingException e) {
- e.printStackTrace();
- return "Unsupported Encoding Text";
- }
- }
- break;
- }
- return input;
- }
- public final byte[] intToByteArray(int value) {
- return new byte[] {
- (byte) (value >>> 24),
- (byte) (value >>> 16),
- (byte) (value >>> 8),
- (byte) (value)
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement