Logo

Programming-Idioms

History of Idiom 63 > diff from v25 to v26

Edit summary for version 26 by :
New Csharp implementation by user [bdadams]

Version 25

2016-02-16, 18:58:34

Version 26

2016-02-18, 16:58:00

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 = x.replace(y, z);
Code
String x2 = x.replace(y, z);
Comments bubble
For regex, use String.replaceAll instead.
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/eCL7ey
Demo URL
https://ideone.com/eCL7ey