stringReplace()

Replaces all occurrences of a pattern within a string with another pattern.

Syntax

public static String stringReplace(String src, String oldpattern, 
       String newPattern)
 

Parameters

src
The string to change.
oldPattern
The character used in padding.
newPattern
The string pattern to use in replacement.

Return values

A new string with the new pattern.

Notes

The method replaces all occurrences of the value specified by oldPattern with the value specified by newPattern. For single character replacement, use the replace() in the Java String class. If oldPattern is not found, the original, unmodified string is returned.

Examples

The following results in youoyou and dad.

stringReplace("momomom and dad", "mom", "you"); 
 

Copyright IBM Corp. 2003