Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static String xmlize(String s) { StringBuffer sb = new StringBuffer(); 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); } } return sb.toString(); } }