![]() |
|
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).
![]() |