diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-11-23 00:35:05 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-11-23 00:35:05 -0500 |
| commit | cb9d3b1a2c2c59c368f6121a16a9ab928b0ff951 (patch) | |
| tree | df4c38c993ff78e2e4005058efb66ee1df6f3561 /api/api.md | |
| parent | a453ebf215e5e3ec3b27fa5142af77d7e3ca0c92 (diff) | |
Added Text.find(text, target, start=1)
Diffstat (limited to 'api/api.md')
| -rw-r--r-- | api/api.md | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -3905,6 +3905,31 @@ assert "hello world".ends_with("world", &remainder) == yes assert remainder == "hello " ``` +## Text.find + +```tomo +Text.find : func(text: Text, target: Text, start: Int = 1 -> Int) +``` + +Find a substring within a text and return its index, if found. + +Argument | Type | Description | Default +---------|------|-------------|--------- +text | `Text` | The text to be searched. | - +target | `Text` | The target text to find. | - +start | `Int` | The index at which to begin searching. | `1` + +**Return:** The index where the first occurrence of `target` appears, or `none` if it is not found. + + +**Example:** +```tomo +assert "one two".find("one") == 1 +assert "one two".find("two") == 5 +assert "one two".find("three") == none +assert "one two".find("o", start=2) == 7 + +``` ## Text.from ```tomo |
