tr/.../.../The Perl tr command can be simulated using Mathematica StringReplace together with the appropriate list of rules. Here is the simplest form where the characters "a", "b", and "c" are replaced by "X", "Y", and "Z" respectively. This generates the appropriate rules in Mathematica using Thread. In[113]:=  |
Out[114]=
|
Here is an example where the replacement list is shorter than the character list, so "d", "e", and "f" are all replaced by "Z". In[115]:=  |
Out[116]=
|
Character ranges in Perl are emulated using CharacterRange in Mathematica. In[117]:=  |
Out[118]=
|
With the /d modifier, the surplus characters are instead deleted. In[119]:=  |
Out[120]=
|
With the /c modifier, the complement of the character list is used. In[121]:=  |
Out[121]=
|
In[122]:=  |
Out[122]=
|
The /s modifier squeezes down to one any run of characters translating into the same character. You get the same effect in Mathematica using Repeated (..). In[123]:=  |
Out[124]=
|
|