fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 296: Replace last occurrence of substring
Idiom # 296: Replace last occurrence of substring
See
programming-idioms.org
:
Code
x2 := match x.find_last y nil => x i i32 => (x.substring 0 i) + (x.substring i).replace y z
What are effects?
Runnable Example
ex296 is x := "AAbbAAbbAAbb" y := "AA" z := "XX" x2 := if !x.contains y then x else i := (x.find_last y).get x.substring(0, i) + (x.substring(i).replace(y, z)) say x say x2
What are effects?
last changed: 2024-07-01
next: NYI: Idiom # 297: Sort a list of strings, case-insensitively