({{, (RefLink[StringReplacePart, paclet:ref/StringReplacePart])["string","snew",{m,n}]
replaces the characters at positions m through n in "string" by "snew". }, {, (RefLink[StringReplacePart, paclet:ref/StringReplacePart])["string","snew",{{(Subscript[m, 1]),(Subscript[n, 1])},{(Subscript[m, 2]),(Subscript[n, 2])},…}]
inserts copies of "snew" at several positions. }, {, (RefLink[StringReplacePart, paclet:ref/StringReplacePart])["string",{"(Subscript[snew, 1])","(Subscript[snew, 2])",…},{{(Subscript[m, 1]),(Subscript[n, 1])},{(Subscript[m, 2]),(Subscript[n, 2])},…}]
replaces characters at positions (Subscript[m, i]) through (Subscript[n, i]) in "string" by "(Subscript[snew, i])". }, {, (RefLink[StringReplacePart, paclet:ref/StringReplacePart])["snew",{m,n}]
represents an operator form of (RefLink[StringReplacePart, paclet:ref/StringReplacePart]) that can be applied to an expression.}})

OpenersNotesSection(Spacer1)Details

(RefLink[StringReplacePart, paclet:ref/StringReplacePart]) uses position specifications in the form returned by (RefLink[StringPosition, paclet:ref/StringPosition]). »

When a list of "(Subscript[snew, i])" is given, its length must be the same as the length of the list of positions. »

When multiple positions are given, all refer to the original "string", before any replacements have been done.

(RefLink[StringReplacePart, paclet:ref/StringReplacePart])[s,"",…] can be used to delete substrings. »

(RefLink[StringReplacePart, paclet:ref/StringReplacePart])[new,part][old] is equivalent to (RefLink[StringReplacePart, paclet:ref/StringReplacePart])[old,new,part].

OpenersPrimaryExamplesSection(Spacer1)Examples  (11)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Replace characters 2 through 5 with a new string:

StringReplacePart["abcdefghijk","ABCDEFGH",{2,5}]

Replace several sequences of characters with a new string:

StringReplacePart["abcdefghijk","ABCDEFGH",{{1,1},{3,5},{-3,-1}}]

Use the operator form of (RefLink[StringReplacePart, paclet:ref/StringReplacePart]):

StringReplacePart["ABCDEFGH",{2,5}]["abcdefghijk"]

OpenersExampleSection1(Spacer1)Scope  (3)

Negative positions count from the end:

StringReplacePart["abcdefghijk","ABCDEFGH",{-3,-2}]

Replace two sequences of characters with two new strings:

StringReplacePart["abcdefghijk",{"XYZ","ABCD"},{{2,3},{-2,-2}}]

Use the operator form to replace two sequences of characters with two new strings:

StringReplacePart[{"XYZ","ABCD"},{{2,3},{-2,-2}}]["abcdefghijk"]

OpenersExampleSection2(Spacer1)Applications  (1)

Simulating a multiway system (WebLink[[more info]:, http://www.wolframscience.com/nksonline/page-937])

step[rule_List,slist_List]:=Union[Flatten[Map[Function[s,Map[step1[#,s]&,rule]],slist]]]

step1[p_String->q_String,s_String]:=Map[StringReplacePart[s,q,#]&,StringPosition[s,p]]

evolvelist[rule_,init_List,t_Integer]:=NestList[step[rule,#]&,init,t]

The evolution of a multiway system:

evolvelist[{"AAB"->"BB","BA"->"ABB"},{"ABBAAB"},3]

OpenersExampleSection3(Spacer1)Properties & Relations  (3)

(RefLink[StringReplacePart, paclet:ref/StringReplacePart]) can use the output from (RefLink[StringPosition, paclet:ref/StringPosition]):

pos=StringPosition["a1b22c333d",DigitCharacter..,Overlaps->False]

StringReplacePart["a1b22c333d","XYZ",pos]

This is equivalent to (RefLink[StringReplace, paclet:ref/StringReplace]):

StringReplace["a1b22c333d",DigitCharacter..->"XYZ"]

Replacing with an empty string is equivalent to (RefLink[StringDrop, paclet:ref/StringDrop]):

StringReplacePart["abcdefghijk","",{2,5}]

StringDrop["abcdefghijk",{2,5}]

(RefLink[StringReplacePart, paclet:ref/StringReplacePart]) can drop several sequences of characters at a time:

StringReplacePart["abcdefghijk","",{{2,5},{7,8},{-1,-1}}]

Use position {n,n-1} to insert at position n, without overwriting anything:

StringReplacePart["abcdefghijk","ABCDEFGH",{3,2}]

(RefLink[StringInsert, paclet:ref/StringInsert]) can do the same:

StringInsert["abcdefghijk","ABCDEFGH",3]

OpenersExampleSection4(Spacer1)Possible Issues  (1)

The position specifications are not allowed to overlap:

StringReplacePart["abcde","XYZ",{{1,3},{3,5}}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[StringInsert, paclet:ref/StringInsert])  ▪  (RefLink[StringDrop, paclet:ref/StringDrop])  ▪  (RefLink[StringReplace, paclet:ref/StringReplace])  ▪  (RefLink[StringJoin, paclet:ref/StringJoin])  ▪  (RefLink[ReplacePart, paclet:ref/ReplacePart])}})}})

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

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

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-NKS.png(Spacer1)NKS|Online, http://www.wolframscience.com/nksonline/index/search.cgi?SearchIndex=StringReplacePart]) ((WebLink[A New Kind of Science, http://www.wolframscience.com/nksonline/]))}})}})