({{, (RefLink[StringInsert, paclet:ref/StringInsert])["string","snew",n]
yields a string with "snew" inserted starting at position n in "string". }, {, (RefLink[StringInsert, paclet:ref/StringInsert])["string","snew",-n]
inserts at position n from the end of "string". }, {, (RefLink[StringInsert, paclet:ref/StringInsert])["string","snew",{(Subscript[n, 1]),(Subscript[n, 2]),…}]
inserts a copy of "snew" at each of the positions (Subscript[n, i]). }, {, (RefLink[StringInsert, paclet:ref/StringInsert])[{(Subscript[s, 1]),(Subscript[s, 2]),…},"snew",n]
gives the list of results for each of the (Subscript[s, i]). }})

OpenersNotesSection(Spacer1)Details

(RefLink[StringInsert, paclet:ref/StringInsert])["string","snew",n] makes the first character of snew the n(^th) character in the new string.

(RefLink[StringInsert, paclet:ref/StringInsert])["string","snew",-n] makes the last character of snew the n(^th) character from the end of the new string.

In (RefLink[StringInsert, paclet:ref/StringInsert])["string","snew",{(Subscript[n, 1]),(Subscript[n, 2]),…}] the (Subscript[n, i]) are taken to refer to positions in "string" before any insertion is done. »

OpenersPrimaryExamplesSection(Spacer1)Examples  (8)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Insert "XYZ" after character position 4:

StringInsert["abcdefghijklm","XYZ",4]

OpenersExampleSection1(Spacer1)Scope  (2)

Insert "XYZ" starting 4 character positions from the end of the string:

StringInsert["abcdefghijklm","XYZ",-4]

Insert "XYZ" at several positions:

StringInsert["abcdefghijklm","XYZ",{2,3,7}]

OpenersExampleSection2(Spacer1)Applications  (1)

Insert a dot at every third character position:

StringInsert["1234567890123456",".",Range[4,16,3]]

Count from the end:

StringInsert["1234567890123456",".",Range[-16,-4,3]]

OpenersExampleSection3(Spacer1)Properties & Relations  (2)

Insertion positions always refer to the original string:

StringInsert["abc","XYZ",{1,2,3}]

Insert "XYZ" to start one character position after the end of the existing string:

StringInsert["abcd","XYZ",5]

An equivalent form:

StringInsert["abcd","XYZ",-1]

OpenersExampleSection4(Spacer1)Possible Issues  (2)

The positions refer to the original string, not the final one:

StringInsert["abcdefghijklm","XYZ",{2,3,7}]

StringPosition[%,"XYZ"]

(RefLink[StringInsert, paclet:ref/StringInsert]) operates on the raw characters in a string:

StringInsert["red","XYZ",10]

FullForm["red"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[StringReplacePart, paclet:ref/StringReplacePart])  ▪  (RefLink[Insert, paclet:ref/Insert])  ▪  (RefLink[StringPosition, paclet:ref/StringPosition])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Operations on Strings, paclet:tutorial/OperationsOnStrings])}, {▪(RefLinkPlain[Special Characters, paclet:tutorial/SpecialCharacters-StringsAndCharacters])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[String Operations, paclet:guide/StringOperations])}})}})