Adds documentation to `substr` function to cover when `length` longer than input `string`

The `substr` function allows the `length` parameter to be longer than the remaining characters in the input after the offset. This is useful for when you want to truncate a string to a maximum number of characters. However, the documentation isn't clear on this so I had to do a test deployment to confirm the behaviour after finding the behaviour in an old issue https://github.com/hashicorp/terraform/issues/15751
This commit is contained in:
Ben Partridge 2022-02-07 15:12:22 +11:00 committed by GitHub
parent d1ac8b71d4
commit fa8a87fab5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -7,7 +7,7 @@ description: |-
# `substr` Function
`substr` extracts a substring from a given string by offset and length.
`substr` extracts a substring from a given string by offset and (maximum) length.
```hcl
substr(string, offset, length)
@ -36,3 +36,11 @@ string after the given offset will be returned.
> substr("hello world", -5, -1)
world
```
The length may be greater than the length of the string, in which case the substring
will be the length of all remaining characters.
```
> substr("hello world", 6, 10)
world
```