From e97c3850b817f6bda6f7ea3fff5c345c5f48bcd8 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 19 Nov 2024 12:59:06 -0500 Subject: [PATCH] Document Text.slice() --- docs/text.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/text.md b/docs/text.md index 5cd0928..6278da2 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:**