1 /* Created on Jan 19, 2004 */
2 package com.quantum.util;
4 import java.util.Arrays;
9 public class StringUtil {
11 public static String substituteString(String original, String placeHolder, String replacementValue) {
12 StringBuffer buffer = new StringBuffer();
13 char[] originalChars = original == null ? new char[0] : original.toCharArray();
14 char[] placeHolderChars = placeHolder.toCharArray();
15 char[] placeHolderComparisonArray = new char[placeHolderChars.length];
17 for (int i = 0, length = originalChars.length; i < length; i++) {
18 if (i <= length - placeHolderChars.length) {
19 System.arraycopy(originalChars, i, placeHolderComparisonArray, 0, placeHolderComparisonArray.length);
20 if (Arrays.equals(placeHolderComparisonArray, placeHolderChars)) {
21 i += placeHolderComparisonArray.length - 1;
22 buffer.append(replacementValue);
24 buffer.append(originalChars[i]);
27 buffer.append(originalChars[i]);
31 return original == null ? null : buffer.toString();