StringReplace
Usage
• StringReplace["string", " " -> " "] 或 StringReplace["string", " " -> " ", " " -> " ", ... ] 用 " "替换 " " ,只要它们作为 "string"的子字符串出现.
Notes
• StringReplace 仔细搜索一个字符串,并检测在每个相继字符位置开始的子字符串.在每个子字符串上,它按顺序尝试你已指定的变换规则. 如果某个规则被应用的话,它就替换该子字符串,然后在该子字符串末尾之后开始新一轮搜索. • 只要每次对一个字符串使用替换时expr都会进行求值,就可以给出形如"s" :> expr 的延时替换. • 选项IgnoreCase -> True 设置使得 StringReplace 把大小写字母看作是等同的.
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]=
|
Here StringReplace is used with delayed replacement.
In[3]:=
|
Out[3]=
|
|