Java tutorial
/** * This software is provided as IS by Antilia-Soft SL. * Copyright 2006-2007. */ //package com.antilia.common.util; public class StringUtils { /** * Add delimiters to a string. * If the string itself contains the delimiter character, * the character will be escaped by repeating the delimitter character. * * @return The delimited String * @param str The String to delimit * @param delimiter */ public static String delimit(String str, char delimiter) { if (delimiter == 0) return (str); StringBuffer buffer = new StringBuffer(); buffer.append(delimiter); if (str != null) { for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == delimiter) buffer.append(delimiter); buffer.append(str.charAt(i)); } } buffer.append(delimiter); return (buffer.toString()); } }