Wednesday, 11 September 2013

How to replace each indice of a substring

How to replace each indice of a substring

String s = "Elephant";
String srep = (s.replaceAll(s.substring(4,6), "_" ));
System.out.println(srep);
So my code outputs Elep_nt But I want it to replace each individual indice
of that substring with an underscore so that it would output Elep__nt is
there anyway to do this in a single line? would I have to use a loop?

No comments:

Post a Comment