diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-11-19 12:59:06 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-11-19 12:59:06 -0500 |
| commit | e97c3850b817f6bda6f7ea3fff5c345c5f48bcd8 (patch) | |
| tree | a23afb17079327992ac3a07e00c12e82f2cfe17f /docs/text.md | |
| parent | af5b5a90d6a1b964fb6d0cc5ff8ef1dc4e1b2f3a (diff) | |
Document Text.slice()
Diffstat (limited to 'docs/text.md')
| -rw-r--r-- | docs/text.md | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/docs/text.md b/docs/text.md index 5cd0928a..6278da2b 100644 --- a/docs/text.md +++ b/docs/text.md @@ -1062,6 +1062,42 @@ replacement text. --- +## `slice` + +**Description:** +Get a slice of the text. + +**Signature:** +```tomo +func slice(text: Text, from: Int = 1, to: Int = -1 -> Text) +``` + +**Parameters:** + +- `text`: The text to be sliced. +- `from`: The index of the first grapheme cluster to include (1-indexed). +- `to`: The index of the last grapheme cluster to include (1-indexed). + +**Returns:** +The text that spans the given grapheme cluster indices. Note: a negative index +counts backwards from the end of the text, so `-1` refers to the last cluster, +`-2` the second-to-last, etc. Slice ranges will be truncated to the length of +the string. + +**Example:** +```tomo +>> "hello":slice(2, 3) += "el" + +>> "hello":slice(to=-2) += "hell" + +>> "hello":slice(from=2) += "ello" +``` + +--- + ## `split` **Description:** |
