Java tutorial
//package com.java2s; public class Main { /** * Escape a string, do entity conversion. */ static String escape(String s) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); switch (c) { case '<': sb.append("<"); break; case '>': sb.append(">"); break; case '&': sb.append("&"); break; case '\'': sb.append("""); break; default: sb.append(c); break; } } return sb.toString(); } }