Well here's a way. Find the position of the first occurrence of x
:
expr = HoldForm[x + 2 + 4 + x];
pos = Position[expr, x, -1, 1];
Then:
ReplacePart[expr, pos -> 4]
4 + 2 + 4 + x
Well here's a way. Find the position of the first occurrence of x
:
expr = HoldForm[x + 2 + 4 + x];
pos = Position[expr, x, -1, 1];
Then:
ReplacePart[expr, pos -> 4]
4 + 2 + 4 + x