Replace First Occurrence Of Character In Android/java?
I would like to take the 's' out of http. https://joy.tothewor.ld/today/and/tommorrow http://joy.tothewor.ld/today/and/tommorrow What's the fastest/less expensive way? substrin
Solution 1:
String.replaceFirst
will do the job.
String output = input.replaceFirst("s","");
Solution 2:
String.replaceFirst
is heavyweight
publicStringreplaceFirst(String regex, String replacement) {
returnPattern.compile(regex).matcher(this).replaceFirst(replacement);
}
this is the fastest way
str = str.substring(0, 4) + s.substring(5);
Solution 3:
You can try this
Stringstr="https://joy.tothewor.ld/today/and/tommorrow"
.replace("https://","http://");
Post a Comment for "Replace First Occurrence Of Character In Android/java?"