| 1 |
--- |
| 2 |
title: strings.SliceString |
| 3 |
description: Returns a substring of the given string, beginning with the start position and ending before the end position. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [slicestr] |
| 9 |
returnType: string |
| 10 |
signatures: ['strings.SliceString STRING [START] [END]'] |
| 11 |
aliases: [/functions/slicestr] |
| 12 |
--- |
| 13 |
|
| 14 |
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. |
| 15 |
|
| 16 |
```go-html-template |
| 17 |
{{ slicestr "BatMan" }} → BatMan |
| 18 |
{{ slicestr "BatMan" 3 }} → Man |
| 19 |
{{ slicestr "BatMan" 0 3 }} → Bat |
| 20 |
``` |
| 21 |
|
| 22 |
The START and END arguments represent the endpoints of a half-open [interval](g), a concept that may be difficult to grasp when first encountered. You may find that the [`strings.Substr`][] function is easier to understand. |
| 23 |
|
| 24 |
[`strings.Substr`]: /functions/strings/substr/ |