I get the HTML Javascript string such as :
htmlString = "https\x3a\x2f\x2ftest.com"
But I want to decode it as below :
str = "https://test.com"
That means , I want a Util API like :
public static String decodeHex(String htmlString){
// do decode and converter here
}
public static void main(String ...args){
String htmlString = "https\x3a\x2f\x2ftest.com";
String str = decodeHex(htmlString);
// str should be "https://test.com"
}
Does anybody know how to implement this API - decodeHex ?
This should be enough to get you started. I leave implementing hexDecode
and sorting out malformed input as an exercise for you.
public String decode(String encoded) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < encoded.length(); i++) {
if (encoded.charAt(i) == '\' && (i + 3) < encoded.length() && encoded.charAt(i + 1) == 'x') {
sb.append(hexDecode(encoded.substring(i + 2, i + 4)));
i += 3;
} else {
sb.append(encoded.charAt(i));
}
}
return sb.toString;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments