Java tutorial
//package com.java2s; /** * Copyright (C) 2011 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ public class Main { private static void append(final StringBuilder sb, final char separator, final char escape, final String component) { if ((component.indexOf(separator) < 0) && (component.indexOf(escape) < 0)) { sb.append(component); } else { for (int j = 0; j < component.length(); j++) { final char c = component.charAt(j); if (c == separator) { sb.append(escape).append(c); } else if (c == escape) { sb.append(c).append(c); } else { sb.append(c); } } } } }