// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Recode {
    private static final Pattern p = Pattern.compile("&#x([0-9A-F]+);");
    public static String code(String s) throws UnsupportedEncodingException {
        String res = s;
        Matcher m = p.matcher(res);
        while(m.find()) {
            res = res.replaceAll(m.group(0), Character.toString((char)Integer.parseInt(m.group(1), 16)));
        }
        return URLEncoder.encode(res, "UTF-8"); 
    }
    public static void main(String[] args) throws Exception {
        System.out.println(Recode.code("Dato&#x2019;"));
    }
}
