/**
* This software is provided as IS by Antilia-Soft SL.
* Copyright 2006-2007.
*/
//package com.antilia.common.util;
public class StringUtils {
/**
* Returns a new string resulting from replacing all occurrences of oldStr in this string with newStr.
*
* @param str
* @param oldStr The old string
* @param newStr the new string
* @return
*/
public static String replace(String str, String oldStr, String newStr) {
if (str == null || str.length() == 0) {
return str;
}
StringBuffer buffer = new StringBuffer();
int pos = 0;
int oldPos = 0;
while ((pos = str.indexOf(oldStr, oldPos)) != -1) {
buffer.append(str.substring(oldPos, pos));
buffer.append(newStr);
oldPos = pos + oldStr.length();
}
buffer.append(str.substring(oldPos, str.length()));
return buffer.toString();
}
}