summaryrefslogtreecommitdiffstats
path: root/docs/content/en/functions/strings
diff options
context:
space:
mode:
Diffstat (limited to 'docs/content/en/functions/strings')
-rw-r--r--docs/content/en/functions/strings/ContainsNonSpace.md4
-rw-r--r--docs/content/en/functions/strings/CountRunes.md2
-rw-r--r--docs/content/en/functions/strings/Diff/diff-screen-capture.pngbin0 -> 7290 bytes
-rw-r--r--docs/content/en/functions/strings/Diff/index.md33
-rw-r--r--docs/content/en/functions/strings/FindRESubmatch.md2
-rw-r--r--docs/content/en/functions/strings/RuneCount.md2
-rw-r--r--docs/content/en/functions/strings/SliceString.md20
-rw-r--r--docs/content/en/functions/strings/Split.md2
-rw-r--r--docs/content/en/functions/strings/Substr.md13
-rw-r--r--docs/content/en/functions/strings/Trim.md2
-rw-r--r--docs/content/en/functions/strings/Truncate.md2
11 files changed, 60 insertions, 22 deletions
diff --git a/docs/content/en/functions/strings/ContainsNonSpace.md b/docs/content/en/functions/strings/ContainsNonSpace.md
index 188aa14ba..d4c72eea0 100644
--- a/docs/content/en/functions/strings/ContainsNonSpace.md
+++ b/docs/content/en/functions/strings/ContainsNonSpace.md
@@ -1,6 +1,6 @@
---
title: strings.ContainsNonSpace
-description: Reports whether the given string contains any non-space characters as defined by Unicode’s White Space property.
+description: Reports whether the given string contains any non-space characters as defined by Unicode's White Space property.
categories: []
keywords: []
action:
@@ -24,7 +24,7 @@ aliases: [/functions/strings.containsnonspace]
{{ strings.ContainsNonSpace "\n abc" }} → true
```
-Common white space characters include:
+Common whitespace characters include:
```text
'\t', '\n', '\v', '\f', '\r', ' '
diff --git a/docs/content/en/functions/strings/CountRunes.md b/docs/content/en/functions/strings/CountRunes.md
index 10788e174..87d9da680 100644
--- a/docs/content/en/functions/strings/CountRunes.md
+++ b/docs/content/en/functions/strings/CountRunes.md
@@ -21,4 +21,4 @@ In contrast with the [`strings.RuneCount`] function, which counts every rune in
{{ "Hello, 世界" | strings.CountRunes }} → 8
```
-[`strings.RuneCount`]: /functions/strings/runecount
+[`strings.RuneCount`]: /functions/strings/runecount/
diff --git a/docs/content/en/functions/strings/Diff/diff-screen-capture.png b/docs/content/en/functions/strings/Diff/diff-screen-capture.png
new file mode 100644
index 000000000..62baa4563
--- /dev/null
+++ b/docs/content/en/functions/strings/Diff/diff-screen-capture.png
Binary files differ
diff --git a/docs/content/en/functions/strings/Diff/index.md b/docs/content/en/functions/strings/Diff/index.md
new file mode 100644
index 000000000..be7bfd911
--- /dev/null
+++ b/docs/content/en/functions/strings/Diff/index.md
@@ -0,0 +1,33 @@
+---
+title: strings.Diff
+description: Returns an anchored diff of the two texts OLD and NEW in the unified diff format. If OLD and NEW are identical, returns an empty string.
+categories: []
+keywords: []
+action:
+ related: []
+ returnType: string
+ signatures: [strings.Diff OLDNAME OLD NEWNAME NEW]
+---
+
+{{< new-in 0.125.0 >}}
+
+Use `strings.Diff` to compare two strings and render a highlighted diff:
+
+```go-html-template
+{{ $want := `
+<p>The product of 6 and 7 is 42.</p>
+<p>The product of 7 and 6 is 42.</p>
+`}}
+
+{{ $got := `
+<p>The product of 6 and 7 is 42.</p>
+<p>The product of 7 and 6 is 13.</p>
+`}}
+
+{{ $diff := strings.Diff "want" $want "got" $got }}
+{{ transform.Highlight $diff "diff" }}
+```
+
+Rendered:
+
+![sreen capture](diff-screen-capture.png)
diff --git a/docs/content/en/functions/strings/FindRESubmatch.md b/docs/content/en/functions/strings/FindRESubmatch.md
index 302d1d9b4..3feb15bbd 100644
--- a/docs/content/en/functions/strings/FindRESubmatch.md
+++ b/docs/content/en/functions/strings/FindRESubmatch.md
@@ -30,7 +30,7 @@ By default, `findRESubmatch` finds all matches. You can limit the number of matc
## Practical example
-This markdown:
+This Markdown:
```text
- [Example](https://example.org)
diff --git a/docs/content/en/functions/strings/RuneCount.md b/docs/content/en/functions/strings/RuneCount.md
index 46fedf01f..86aab0c64 100644
--- a/docs/content/en/functions/strings/RuneCount.md
+++ b/docs/content/en/functions/strings/RuneCount.md
@@ -21,4 +21,4 @@ In contrast with the [`strings.CountRunes`] function, which excludes whitespace,
{{ "Hello, 世界" | strings.RuneCount }} → 9
```
-[`strings.CountRunes`]: /functions/strings/countrunes
+[`strings.CountRunes`]: /functions/strings/countrunes/
diff --git a/docs/content/en/functions/strings/SliceString.md b/docs/content/en/functions/strings/SliceString.md
index 2f33f8f65..ee4ed9081 100644
--- a/docs/content/en/functions/strings/SliceString.md
+++ b/docs/content/en/functions/strings/SliceString.md
@@ -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&nbsp;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/
diff --git a/docs/content/en/functions/strings/Split.md b/docs/content/en/functions/strings/Split.md
index a9973ea63..e3e0ee13e 100644
--- a/docs/content/en/functions/strings/Split.md
+++ b/docs/content/en/functions/strings/Split.md
@@ -22,5 +22,5 @@ Examples:
{{% note %}}
The `strings.Split` function essentially does the opposite of the [`collections.Delimit`] function. While `split` creates a slice from a string, `delimit` creates a string from a slice.
-[`collections.Delimit`]: /functions/collections/delimit
+[`collections.Delimit`]: /functions/collections/delimit/
{{% /note %}}
diff --git a/docs/content/en/functions/strings/Substr.md b/docs/content/en/functions/strings/Substr.md
index 6c1852f58..19a029e28 100644
--- a/docs/content/en/functions/strings/Substr.md
+++ b/docs/content/en/functions/strings/Substr.md
@@ -1,21 +1,20 @@
---
title: strings.Substr
-description: Extracts parts of a string from a specified character's position and returns the specified number of characters.
+description: Returns a substring of the given string, beginning with the start position and ending after the given length.
categories: []
keywords: []
action:
aliases: [substr]
- related: []
+ related:
+ - functions/strings/SliceString
returnType: string
- signatures: ['strings.Substr STRING START [LENGTH]']
+ signatures: ['strings.Substr STRING [START] [LENGTH]']
aliases: [/functions/substr]
---
-It normally takes two argument: `start` and `length`. It can also take one argument: `start`, i.e. `length` is omitted, in which case the substring starting from start until the end of the string will be returned.
+The start position is zero-based, where `0` represents the first character of the string. If START is not specified, the substring will begin at position `0`. Specify a negative START position to extract characters from the end of the string.
-To extract characters from the end of the string, use a negative start number.
-
-If `length` is given and is negative, that number of characters will be omitted from the end of string.
+If LENGTH is not specified, the substring will include all characters from the START position to the end of the string. If negative, that number of characters will be omitted from the end of string.
```go-html-template
{{ substr "abcdef" 0 }} → abcdef
diff --git a/docs/content/en/functions/strings/Trim.md b/docs/content/en/functions/strings/Trim.md
index 6dfac024b..9a87ff206 100644
--- a/docs/content/en/functions/strings/Trim.md
+++ b/docs/content/en/functions/strings/Trim.md
@@ -32,7 +32,7 @@ To remove leading and trailing newline characters and carriage returns:
The `strings.Trim` function is commonly used in shortcodes to remove leading and trailing newlines characters and carriage returns from the content within the opening and closing shortcode tags.
-For example, with this markdown:
+For example, with this Markdown:
```text
{{</* my-shortcode */>}}
diff --git a/docs/content/en/functions/strings/Truncate.md b/docs/content/en/functions/strings/Truncate.md
index 17ae0afc6..2e7693eb5 100644
--- a/docs/content/en/functions/strings/Truncate.md
+++ b/docs/content/en/functions/strings/Truncate.md
@@ -20,5 +20,5 @@ Since Go templates are HTML-aware, `truncate` will intelligently handle normal s
{{% note %}}
If you have a raw string that contains HTML tags you want to remain treated as HTML, you will need to convert the string to HTML using the [`safeHTML`]function before sending the value to `truncate`. Otherwise, the HTML tags will be escaped when passed through the `truncate` function.
-[`safeHTML`]: /functions/safe/html
+[`safeHTML`]: /functions/safe/html/
{{% /note %}}