strings.SliceString
Returns a substring of the given string, beginning with the start position and ending before the end position.
- Syntax
- strings.SliceString STRING [START] [END]
- Returns
- string
- Alias
- slicestr
Usage
The strings.SliceString function returns a substring of the given string, beginning with the start position and ending before the end position. The START and END positions are zero-based, where 0 represents the first character of the string. If you omit START, the substring begins at position 0. If you omit END, the substring ends after the last character.
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.
Examples
{{ strings.SliceString "BatMan" }} → BatMan
{{ strings.SliceString "BatMan" 3 }} → Man
{{ strings.SliceString "BatMan" 0 3 }} → BatLast updated:
October 28, 2026
:
content: Apply style guide to strings functions (d6de31ebd)
Improve this page