Navigation
Synopsis Replace the first occurrence of a string in another string.
Function str replaceFirst(str subject, str find, str replacement)
Usage import String;
Description Return a copy of subject in which the first occurrence of find (if it exists) has been replaced by replacement. Also see replaceAll and replaceLast.
Examples
rascal>import String;
ok
rascal>replaceFirst("abracadabra", "a", "A");
str: "Abracadabra"
rascal>replaceFirst("abracadabra", "ra", "RARA");
str: "abRARAcadabra"
rascal>replaceFirst("abracadabra", "cra", "CRA");
str: "abracadabra"
Pitfalls Note that find is a string (as opposed to, for instance, a regular expression in Java).
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.