Logo

Programming-Idioms

History of Idiom 63 > diff from v22 to v23

Edit summary for version 23 by :
New Java implementation by user [lck]

Version 22

2015-11-30, 12:37:30

Version 23

2016-01-04, 04:33:30

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);
Comments bubble
use String.replaceAll for regex replace.
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