Logo

Programming-Idioms

History of Idiom 63 > diff from v3 to v4

Edit summary for version 4 by :

Version 3

2015-05-06, 21:04:51

Version 4

2015-07-31, 19:33:28

Idiom #63 Replace fragment of a string

Assign to x2 the value of string x with all occurrences of y replaced by z.

Idiom #63 Replace fragment of a string

Assign to x2 the value of string x with all occurrences of y replaced by z.

Code
substr($a, 5, 2) = "replacement text";
Comments bubble
You can use substr on the left side of the equation. Here, we'll replace the two characters at position 5 with the phrase "replacement text". Yes, the replacement text can be of a different length.