Evaluate

Basic Examples

Replace parts 1, 3, and 4 with the rule
ce
:
[◼]
ReplacePartWith
[{c,b,c,d},ce,{{1},{3},{4}}]
In[]:=
{e,b,e,d}
Out[]=

Properties and Relations

ReplacePartWith
takes lists of positions in the same form as generated by
Position
:
Position[{a,b,x,c,d,x,e},x]
In[]:=
{{3},{6}}
Out[]=
[◼]
ReplacePartWith
[{a,b,x,c,d,x,e},{xyy},{{3},{6}}]
In[]:=
{a,b,yy,c,d,yy,e}
Out[]=
ReplacePart
replaces parts of an expression. Exactly what the part is replaced with is specified in advance:
ReplacePart[{c,b,c,d},{1e,2f,3g}]
In[]:=
{e,f,g,d}
Out[]=
ReplacePartWith
replaces parts of an expression, and what is replaced is determined by the applied rule:
[◼]
ReplacePartWith
[{c,b,c,d},ce,{{1},{3},{4}}]
In[]:=
{e,b,e,d}
Out[]=

Possible Issues

Replacing an empty list of positions does not change the expression:
[◼]
ReplacePartWith
[h[a,b],_x,{}]
In[]:=
h[a,b]
Out[]=
Position
{}
corresponds to the whole expression:
[◼]
ReplacePartWith
[h[a,b],_x,{{}}]
In[]:=
x
Out[]=