Java String Unescape unescape(String str)

Here you can find the source of unescape(String str)

Description

unescape

License

LGPL

Declaration

public static String unescape(String str) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    public static String unescape(String str) {
        if (str == null) {
            return str;
        }//from   w w  w  .ja va2 s . c o  m

        String temp = str, sub;
        temp = "";
        char ch = ' ';
        int index = str.indexOf("%u");

        while (index >= 0) {
            temp += str.substring(0, index);
            sub = str.substring(index + 2, index + 6);
            str = str.substring(index + 6, str.length());

            try {
                ch = (char) Integer.parseInt(sub, 16);
                temp += new String(new char[] { ch });
            } catch (NumberFormatException e) {
                temp += sub;
            }
            index = str.indexOf("%u");
        }

        temp += str;
        //      temp = URLDecoder.decode(temp);

        index = temp.indexOf("%");
        String temp1 = "";
        while (index >= 0) {
            temp1 += temp.substring(0, index);
            sub = temp.substring(index + 1, index + 3);
            temp = temp.substring(index + 3, temp.length());

            try {
                ch = (char) Integer.parseInt(sub, 16);
                temp1 += new String(new char[] { ch });
            } catch (NumberFormatException e) {
                temp1 += sub;
            }
            index = temp.indexOf("%");
        }

        temp1 += temp;
        return temp1;
    }
}

Related

  1. unescape(String str)
  2. unescape(String str)
  3. unescape(String str)
  4. unescape(String str)
  5. unescape(String str)
  6. unescape(String str)
  7. unescape(String str)
  8. unescape(String str)
  9. unescape(String str)