Wolfram ResearchPRODUCTSPURCHASEFOR USERSCOMPANYOUR SITES
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.

StringReplace

Usage
Notes
Further Examples

This replaces each occurrence of the string "ab" with the string "efg"; "Ab" does not match "ab".

In[1]:=  

Out[1]=

With IgnoreCase set to True, "Ab" now matches "ab".

In[2]:=  

Out[2]=

Named patterns can be used on the right hand side of the rule. This capitalizes each word in the sentence.

In[3]:=  

Out[3]=

The same can be done with RegularExpression, using $n to refer to the n parenthesized subpattern.

In[4]:=  

Out[4]=

This strips off all tags "<...>" from an HTML document.

In[5]:=  

Out[5]=

This trims white space off ends of strings.

In[6]:=  

Out[6]//InputForm=

This squares all the numbers that appear in the string.

In[7]:=  

Out[7]=

Here StringReplace is used with delayed replacement.

In[8]:=  

Out[8]=

StringReplace applies the set of rules exactly once on each part of a string.

In[9]:=  

Out[9]=

This defines the function StringReplaceRepeated which uses StringReplace repeatedly until the string stops changing.

In[10]:=  

In[11]:=  

Out[11]=

Replacements do not have to be strings, so a string expression can be generated for further use.

In[12]:=  

Out[12]=

This fills in the template with data.

In[13]:=  

Out[13]=

In[14]:=  


Any questions about topics on this page? Click here to get an individual response.Buy NowFree TrialMore Information



 © 2009 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: