Java tutorial
//package com.java2s; public class Main { public static String getTagName(final String tag) { final StringBuilder result = new StringBuilder(); for (int i = 0; i < tag.length(); i++) { final char character = tag.charAt(i); switch (character) { case '<': result.append("<"); break; case '>': result.append(">"); break; case '\"': result.append("""); break; case '\'': result.append("'"); break; case '\\': result.append("\"); break; case '&': result.append("&"); break; case ' ': break; default: result.append(character); } } return result.toString(); } }