Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > String Manipulation > String Operations >

StringInsert

StringInsert["string", "snew", n]
yields a string with "snew" inserted starting at position n in "string".
StringInsert["string", "snew", -n]
inserts at position n from the end of "string".
StringInsert["string", "snew", {n1, n2, ...}]
inserts a copy of "snew" at each of the positions n_i.
StringInsert[{s1, s2, ...}, "snew", n]
gives the list of results for each of the s_i.
  • StringInsert["string", "snew", n] makes the first character of snew the n^(th) character in the new string.
  • StringInsert["string", "snew", -n] makes the last character of snew the n^(th) character from the end of the new string.
  • In StringInsert["string", "snew", {n1, n2, ...}] the ni are taken to refer to positions in "string" before any insertion is done.  »
Insert XYZ after character position 4:
Insert XYZ after character position 4:
In[1]:=
Click for copyable input
Out[1]=
Insert XYZ starting 4 character positions from the end of the string:
Insert XYZ at several positions:
Insert a dot at every third character position:
Count from the end:
Insertion positions always refer to the original string:
Insert XYZ to start one character position after the end of the existing string:
An equivalent form:
The positions refer to the original string, not the final one:
StringInsert operates on the raw characters in a string:
New in 2 | Last modified in 5.1
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team