From b77011c93bdadace1c219a4d9cdee948c767d0cd Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Thu, 11 Apr 2024 12:05:25 -0700 Subject: [PATCH] Improve function descriptions --- content/en/functions/strings/SliceString.md | 16 +++++++++++----- content/en/functions/strings/Substr.md | 13 ++++++------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/content/en/functions/strings/SliceString.md b/content/en/functions/strings/SliceString.md index 2f33f8f65..6e720c550 100644 --- a/content/en/functions/strings/SliceString.md +++ b/content/en/functions/strings/SliceString.md @@ -1,20 +1,26 @@ --- title: strings.SliceString -description: Creates a slice of a half-open range, including start and end indices. +description: Returns a substring of the given string, beginning with the start position and ending before the end position. categories: [] keywords: [] action: aliases: [slicestr] - related: [] + related: + - functions/strings/Substr returnType: string - signatures: ['strings.SliceString STRING START [END]'] + signatures: ['strings.SliceString STRING [START] [END]'] aliases: [/functions/slicestr] --- -For example, 1 and 4 creates a slice including elements 1 through 3. -The `end` index can be omitted; it defaults to the string's length. +The START and END positions are zero-based, where `0` represents the first character of the string. If START is not specified, the substring will begin at position `0`. If END is not specified, the substring will end after the last character. ```go-html-template +{{ slicestr "BatMan" }}` → BatMan {{ slicestr "BatMan" 3 }}` → Man {{ slicestr "BatMan" 0 3 }}` → Bat ``` + +The START and END arguments represent the endpoints of a [half-open interval], a concept that may be difficult to grasp when first encountered. You may find that the [`strings.Substr`] function is easier to understand. + +[half-open interval]: /getting-started/glossary/#interval +[`strings.Substr`]: /functions/strings/substr/ diff --git a/content/en/functions/strings/Substr.md b/content/en/functions/strings/Substr.md index 6c1852f58..19a029e28 100644 --- a/content/en/functions/strings/Substr.md +++ b/content/en/functions/strings/Substr.md @@ -1,21 +1,20 @@ --- title: strings.Substr -description: Extracts parts of a string from a specified character's position and returns the specified number of characters. +description: Returns a substring of the given string, beginning with the start position and ending after the given length. categories: [] keywords: [] action: aliases: [substr] - related: [] + related: + - functions/strings/SliceString returnType: string - signatures: ['strings.Substr STRING START [LENGTH]'] + signatures: ['strings.Substr STRING [START] [LENGTH]'] aliases: [/functions/substr] --- -It normally takes two argument: `start` and `length`. It can also take one argument: `start`, i.e. `length` is omitted, in which case the substring starting from start until the end of the string will be returned. +The start position is zero-based, where `0` represents the first character of the string. If START is not specified, the substring will begin at position `0`. Specify a negative START position to extract characters from the end of the string. -To extract characters from the end of the string, use a negative start number. - -If `length` is given and is negative, that number of characters will be omitted from the end of string. +If LENGTH is not specified, the substring will include all characters from the START position to the end of the string. If negative, that number of characters will be omitted from the end of string. ```go-html-template {{ substr "abcdef" 0 }} → abcdef