public static StringBuffer replace( StringBuffer out, String s, String repl, String with) { int lastindex = 0; int len = repl.length(); for (int index = s.indexOf(repl); index >= 0; index = s.indexOf(repl, lastindex = index + len)) { // we have search string at position index out.append(substring(s, lastindex, index)).append(with); } return out.append(substring(s, lastindex, len)); }
public static StringBuffer replace( StringBuffer out, String s, String repl, String with) { int lastindex = 0; int len = repl.length(); for (int index = s.indexOf(repl); index >= 0; index = s.indexOf(repl, lastindex = index + len)) { // we have search string at position index out.append(substring(s, lastindex, index)).append(with); } return out.append(substring(s, lastindex, len)); }
public static StringBuffer replace( StringBuffer out, String s, String repl, String with) { int lastindex = 0; int len = repl.length(); for (int index = s.indexOf(repl); index >= 0; index = s.indexOf(repl, lastindex = index + len)) { // we have search string at position index out.append(substring(s, lastindex, index)).append(with); } return out.append(substring(s, lastindex, len)); }
public static String replace(String str, String repl, String with) { int lastindex = 0; int pos = str.indexOf(repl); // If no replacement needed, return the original string // and save StringBuffer allocation/char copying if (pos < 0) { return str; } int len = repl.length(); int lendiff = with.length() - repl.length(); StringBuffer out = new StringBuffer((lendiff <= 0) ? str.length() : (str.length() + (10 * lendiff))); for (; pos >= 0; pos = str.indexOf(repl, lastindex = pos + len)) { out.append(substring(str, lastindex, pos)).append(with); } return out.append(substring(str, lastindex, str.length())).toString(); }
public static String replace(String str, char repl, String with) { int pos = str.indexOf(repl); // If no replacement needed, return the original string // and save StringBuffer allocation/char copying if (pos < 0) { return str; } int len = str.length(); int lendiff = with.length() - 1; StringBuffer out = new StringBuffer((lendiff <= 0) ? str.length() : (str.length() + (10 * lendiff))); int lastindex = 0; for (; pos >= 0; pos = str.indexOf(repl, lastindex = pos + 1)) { out.append(substring(str, lastindex, pos)).append(with); } return out.append(substring(str, lastindex, len)).toString(); }
public static String replace(String str, char repl, String with) { int pos = str.indexOf(repl); // If no replacement needed, return the original string // and save StringBuffer allocation/char copying if (pos < 0) { return str; } int len = str.length(); int lendiff = with.length() - 1; StringBuffer out = new StringBuffer((lendiff <= 0) ? str.length() : (str.length() + (10 * lendiff))); int lastindex = 0; for (; pos >= 0; pos = str.indexOf(repl, lastindex = pos + 1)) { out.append(substring(str, lastindex, pos)).append(with); } return out.append(substring(str, lastindex, len)).toString(); }
public static String replace(String str, String repl, String with) { int lastindex = 0; int pos = str.indexOf(repl); // If no replacement needed, return the original string // and save StringBuffer allocation/char copying if (pos < 0) { return str; } int len = repl.length(); int lendiff = with.length() - repl.length(); StringBuffer out = new StringBuffer((lendiff <= 0) ? str.length() : (str.length() + (10 * lendiff))); for (; pos >= 0; pos = str.indexOf(repl, lastindex = pos + len)) { out.append(substring(str, lastindex, pos)).append(with); } return out.append(substring(str, lastindex, str.length())).toString(); }
public static String replace(String str, String repl, String with) { int lastindex = 0; int pos = str.indexOf(repl); // If no replacement needed, return the original string // and save StringBuffer allocation/char copying if (pos < 0) { return str; } int len = repl.length(); int lendiff = with.length() - repl.length(); StringBuffer out = new StringBuffer((lendiff <= 0) ? str.length() : (str.length() + (10 * lendiff))); for (; pos >= 0; pos = str.indexOf(repl, lastindex = pos + len)) { out.append(substring(str, lastindex, pos)).append(with); } return out.append(substring(str, lastindex, str.length())).toString(); }
/** * Split a string into an array of strings arround a character separator. * This function will be efficient for longer strings * * @param str the string to be split * @param separator the separator character * * @return array of string subparts */ public static String[] splitLongString(String str, char separator) { int len; if (str == null || (len = str.length()) == 0) { return ArrayUtils.EMPTY_STRING_ARRAY; } int oldPos = 0; ArrayList list = new ArrayList(); for ( int pos = str.indexOf(separator); pos >= 0; pos = str.indexOf(separator, (oldPos = (pos + 1)))) { list.add(substring(str, oldPos, pos)); } list.add(substring(str, oldPos, len)); return (String[]) list.toArray(ArrayUtils.EMPTY_STRING_ARRAY); }
/** * Split a string into an array of strings arround a character separator. * This function will be efficient for longer strings * * @param str the string to be split * @param separator the separator character * * @return array of string subparts */ public static String[] splitLongString(String str, char separator) { int len; if (str == null || (len = str.length()) == 0) { return ArrayUtils.EMPTY_STRING_ARRAY; } int oldPos = 0; ArrayList list = new ArrayList(); for ( int pos = str.indexOf(separator); pos >= 0; pos = str.indexOf(separator, (oldPos = (pos + 1)))) { list.add(substring(str, oldPos, pos)); } list.add(substring(str, oldPos, len)); return (String[]) list.toArray(ArrayUtils.EMPTY_STRING_ARRAY); }
public static String replace(String str, char repl, String with) { int pos = str.indexOf(repl); // If no replacement needed, return the original string // and save StringBuffer allocation/char copying if (pos < 0) { return str; } int len = str.length(); int lendiff = with.length() - 1; StringBuffer out = new StringBuffer((lendiff <= 0) ? str.length() : (str.length() + (10 * lendiff))); int lastindex = 0; for (; pos >= 0; pos = str.indexOf(repl, lastindex = pos + 1)) { out.append(substring(str, lastindex, pos)).append(with); } return out.append(substring(str, lastindex, len)).toString(); }
/** * Split a string into an array of strings arround a character separator. * This function will be efficient for longer strings * * @param str the string to be split * @param separator the separator character * * @return array of string subparts */ public static String[] splitLongString(String str, char separator) { int len; if (str == null || (len = str.length()) == 0) { return ArrayUtils.EMPTY_STRING_ARRAY; } int oldPos = 0; ArrayList list = new ArrayList(); for ( int pos = str.indexOf(separator); pos >= 0; pos = str.indexOf(separator, (oldPos = (pos + 1)))) { list.add(substring(str, oldPos, pos)); } list.add(substring(str, oldPos, len)); return (String[]) list.toArray(ArrayUtils.EMPTY_STRING_ARRAY); }
public static String dequoteFull(String str, int begin, int end, char quote) { // If empty substring, return empty string if (begin == end) { return ""; } // If not quoted, return string if (str.charAt(begin) != quote) { return str.substring(begin, end); } int _end = end - 1; if ((str.length() < 2) || (str.charAt(_end) != quote)) { throw new IllegalArgumentException( "Closing quote missing in string '" + substring(str, begin, end) + "'"); } return dequote(str, begin + 1, _end, quote); }
public static String dequoteFull(String str, int begin, int end, char quote) { // If empty substring, return empty string if (begin == end) { return ""; } // If not quoted, return string if (str.charAt(begin) != quote) { return str.substring(begin, end); } int _end = end - 1; if ((str.length() < 2) || (str.charAt(_end) != quote)) { throw new IllegalArgumentException( "Closing quote missing in string '" + substring(str, begin, end) + "'"); } return dequote(str, begin + 1, _end, quote); }
public static String dequoteFull(String str, int begin, int end, char quote) { // If empty substring, return empty string if (begin == end) { return ""; } // If not quoted, return string if (str.charAt(begin) != quote) { return str.substring(begin, end); } int _end = end - 1; if ((str.length() < 2) || (str.charAt(_end) != quote)) { throw new IllegalArgumentException( "Closing quote missing in string '" + substring(str, begin, end) + "'"); } return dequote(str, begin + 1, _end, quote); }