fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 62: Find substring position
Idiom # 62: Find substring position
See
programming-idioms.org
:
Code
i := x.find y
What are effects?
Running Example
ex62 is find (x, y String) => i := x.find y say "found '$y' in '$x' at index $i" find "Hallo" "allo" find "Hallo" "allô" find ("a" * 16 ) ("a" * 7 + "b") find ("a" * 16 + "b") ("a" * 7 + "b") find ("a" * 32 ) ("a" * 15 + "b") find ("a" * 32 + "b") ("a" * 15 + "b") find ("a" * 64 ) ("a" * 31 + "b") find ("a" * 64 + "b") ("a" * 31 + "b") find ("a" * 128 ) ("a" * 63 + "b") find ("a" * 128 + "b") ("a" * 63 + "b") find ("a" * 256 ) ("a" * 127 + "b") find ("a" * 256 + "b") ("a" * 127 + "b") find ("a" * 512 ) ("a" * 255 + "b") find ("a" * 512 + "b") ("a" * 255 + "b") abc := "abcdefghijklmnopqrstuvwxyz" str := "the quick brown fox jumps over the lazy dog" for i in 0..(abc.byte_length-1) do s := abc.substring i i+1 match str.find s nil => say "$s not found" ix i32 => m := "found '$s' at index $ix: " say (m + str) say "{ "-" * (m.codepoint_length + ix) }^"
What are effects?
last changed: 2024-07-01
next: Idiom # 63: Replace fragment of a string