Logo

Programming-Idioms

History of Idiom 63 > diff from v23 to v24

Edit summary for version 24 by :
[Java] x2 + demo with exact variable names

Version 23

2016-01-04, 04:33:30

Version 24

2016-01-04, 11:29:27

Idiom #63 Replace fragment of a string

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

Idiom #63 Replace fragment of a string

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

Code
String x2 = s.replace(y, z);
Code
String x2 = x.replace(y, z);
Comments bubble
use String.replaceAll for regex replace.
Comments bubble
For regex, use String.replaceAll instead.
Doc URL
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#replace-java.lang.CharSequence-java.lang.CharSequence-
Doc URL
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#replace-java.lang.CharSequence-java.lang.CharSequence-
Demo URL
https://ideone.com/j2CqdM
Demo URL
https://ideone.com/eCL7ey