replaceFirst method
Returns a new String
with the first occurrence of the given pattern replaced with the replacement String
.
If the String
is null
, an ArgumentError
is thrown.
Example
String s = "esentis".replaceFirst("s", "S"); // returns "eSentis";
Implementation
String replaceFirst(String pattern, String replacement) {
int index = this.indexOf(pattern);
if (index == -1) {
return this;
}
return this.replaceRange(index, index + pattern.length, replacement);
}