// 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) 
public class HtmlEscape {
    public static String encode(String s) {
        StringBuffer sb = new StringBuffer("");
        for(int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if((c >= 0) && (c <=127)) {
                sb.append(c);
            } else {
                sb.append("&#" + Integer.toHexString(c) + ";");
            }
        }
        return sb.toString();
    }
    public static void main(String[] args) {
        System.out.println(encode("ÆØÅæøå\u1234"));
    }
}
