| 1 |
--- |
| 2 |
title: PlainWords |
| 3 |
description: Returns a slice of words created by calling the Plain method and splitting the result. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: '[]string' |
| 9 |
signatures: [PAGE.PlainWords] |
| 10 |
--- |
| 11 |
|
| 12 |
The `PlainWords` method on a `Page` object calls the [`Plain`][] method, then uses Go's [`strings.Fields`][] function to split the result into words. |
| 13 |
|
| 14 |
> [!NOTE] |
| 15 |
> `Fields` splits the string `s` around each instance of one or more consecutive whitespace characters, as defined by [`unicode.IsSpace`][], returning a slice of substrings of `s` or an empty slice if `s` contains only whitespace. |
| 16 |
|
| 17 |
As a result, elements within the slice may contain leading or trailing punctuation. |
| 18 |
|
| 19 |
```go-html-template |
| 20 |
{{ .PlainWords }} |
| 21 |
``` |
| 22 |
|
| 23 |
To determine the approximate number of unique words on a page: |
| 24 |
|
| 25 |
```go-html-template |
| 26 |
{{ .PlainWords | uniq }} → 42 |
| 27 |
``` |
| 28 |
|
| 29 |
[`Plain`]: /methods/page/plain/ |
| 30 |
[`strings.Fields`]: https://pkg.go.dev/strings#Fields |
| 31 |
[`unicode.IsSpace`]: https://pkg.go.dev/unicode#IsSpace |