This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)


StringReplace["string", s->sp] or StringReplace["string", {s1->sp1, s2->sp2, ...}]
replaces the string expressions si by spi whenever they appear as substrings of "string".
StringReplace["string", srules, n]
does only the first n replacements.
StringReplace[{s1, s2, ...}, srules]
gives the list of results for each of the si.
  • The string expressions si can contain any of the objects specified in the notes for StringExpression.
  • StringReplace goes through a string, testing substrings that start at each successive character position. On each substring, it tries in turn each of the transformation rules you have specified. If any of the rules apply, it replaces the substring, then continues to go through the string, starting at the character position after the end of the substring.
  • In replacements of the form si:>spi, the spi are not evaluated until each time they are used.
New in 2 | Last modified in 5.1