Java Utililty Methods String Replace

List of utility methods to do String Replace

Description

The list of methods to do String Replace are organized into topic(s).

Method

StringreplaceWildcards(String wildcardPattern)
replace Wildcards
final StringBuilder builder = new StringBuilder();
builder.append('^');
boolean replaced = false;
final int length = wildcardPattern.length();
for (int i = 0; i < length; ++i) {
    final char ch = wildcardPattern.charAt(i);
    if (ch == '*') {
        builder.append(".*");
...
StringsearchAndReplace(String source, String search, String replace)
Searches for various instances of the 'search' string and replaces them with the 'replace' string.
return implode(explode(source, search), replace);
StringstrReplaceOld(String strText, String strFrom, String strTo, boolean bMultiple)
Old version of strReplace.
int iFromLength = strFrom.length();
int iToLength = strTo.length();
int iOccurs = 0;
String strOutput = new String(strText);
iOccurs = strOutput.toLowerCase().indexOf(strFrom.toLowerCase(), 0);
int iStartWith = 0;
while (iOccurs != -1) {
    strOutput = strOutput.substring(0, iOccurs) + strTo + strOutput.substring(iOccurs + iFromLength);
...
StringsubStitute(String value, String pattern, String replacement)
sub Stitute
if (value == null || value.length() == 0)
    return value;
if (pattern == null || pattern.length() == 0)
    return value;
StringBuffer sb = new StringBuffer();
do {
    int patternIndex = value.indexOf(pattern);
    if (patternIndex == -1) {
...
StringsubstituteIgnoreCase(String s, String pattern, String replacement)
Substitutes alls occurences of a pattern in a string, ignores character casing.
if (s == null || pattern == null)
    return s;
int patLen = pattern.length();
if (patLen == 0)
    return s;
StringBuffer sb = null;
int len = s.length();
for (int i = 0; i < len; ++i) {
...