trim.md (1083B)
1 ---
2 title: trim
3 # linktitle:
4 description: Returns a slice of a passed string with all leading and trailing characters from cutset removed.
5 date: 2017-02-01
6 publishdate: 2017-02-01
7 lastmod: 2017-02-01
8 categories: [functions]
9 menu:
10 docs:
11 parent: "functions"
12 keywords: [strings]
13 signature: ["trim INPUT CUTSET"]
14 workson: []
15 hugoversion:
16 relatedfuncs: []
17 deprecated: false
18 ---
19
20 ```
21 {{ trim "++Batman--" "+-" }} → "Batman"
22 ```
23
24 `trim` *requires* the second argument, which tells the function specifically what to remove from the first argument. There is no default value for the second argument, so **the following usage will not work**:
25
26 ```
27 {{ trim .Inner}}
28 ```
29
30 Instead, the following example tells `trim` to remove extra new lines from the content contained in the [shortcode `.Inner` variable][shortcodevars]:
31
32 ```
33 {{ trim .Inner "\n" }}
34 ```
35
36 {{% note %}}
37 Go templates also provide a simple [method for trimming whitespace](/templates/introduction/#whitespace) from either side of a Go tag by including a hyphen (`-`).
38 {{% /note %}}
39
40
41 [shortcodevars]: /variables/shortcodes/