/**
* Replace all occurence of forReplace with replaceWith in input string.
*
* @param input
* represents input string
* @param forReplace
* represents substring for replace
* @param replaceWith
* represents replaced string value
* @return new string with replaced values
*/
private static String replaceAll(String input, String forReplace,
String replaceWith) {
if (input == null)
return null;
StringBuffer result = new StringBuffer();
boolean hasMore = true;
while (hasMore) {
int start = input.indexOf(forReplace);
int end = start + forReplace.length();
if (start != -1) {
result.append(input.substring(0, start) + replaceWith);
input = input.substring(end);
} else {
hasMore = false;
result.append(input);
}
}
if (result.toString().equals(""))
return input; // nothing is changed
else
return result.toString();
}