mirror of
https://github.com/gohugoio/hugo.git
synced 2025-05-02 00:20:21 +03:00
Merge commit '8b9803425e
'
This commit is contained in:
commit
af0cb57aaf
475 changed files with 7408 additions and 4720 deletions
|
@ -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" 3 }}` → Man
|
||||
{{ slicestr "BatMan" 0 3 }}` → Bat
|
||||
{{ 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/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue