From 975ff1d09077f29da003729a8df8b1c88da51cf8 Mon Sep 17 00:00:00 2001 From: Raimar Falke Date: Thu, 24 Oct 2024 18:52:15 +0000 Subject: [PATCH] backport of commit cad5b574052e97ff569d2ec5c1c53b40c2825ae6 --- website/docs/language/functions/trimprefix.mdx | 7 ++++++- website/docs/language/functions/trimsuffix.mdx | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/website/docs/language/functions/trimprefix.mdx b/website/docs/language/functions/trimprefix.mdx index 51b931bdb167..195cacd455a2 100644 --- a/website/docs/language/functions/trimprefix.mdx +++ b/website/docs/language/functions/trimprefix.mdx @@ -7,7 +7,7 @@ description: |- # `trimprefix` Function -`trimprefix` removes the specified prefix from the start of the given string. If the string does not start with the prefix, the string is returned unchanged. +`trimprefix` removes the specified prefix from the start of the given string, but only once. If the string does not begin with the prefix, the original string is returned unchanged. ## Examples @@ -21,6 +21,11 @@ world helloworld ``` +``` +> trimprefix("--hello", "-") +-hello +``` + ## Related Functions * [`trim`](/terraform/language/functions/trim) removes characters at the start and end of a string. diff --git a/website/docs/language/functions/trimsuffix.mdx b/website/docs/language/functions/trimsuffix.mdx index 31f12f225a5e..272d0cc48e7c 100644 --- a/website/docs/language/functions/trimsuffix.mdx +++ b/website/docs/language/functions/trimsuffix.mdx @@ -7,7 +7,7 @@ description: |- # `trimsuffix` Function -`trimsuffix` removes the specified suffix from the end of the given string. +`trimsuffix` removes the specified suffix from the end of the given string, but only once, even if the suffix appears multiple times. If the suffix does not appear at the very end of the string, the original string is returned unchanged. ## Examples @@ -16,6 +16,16 @@ description: |- hello ``` +``` +> trimsuffix("helloworld", "cat") +helloworld +``` + +``` +> trimsuffix("hello--", "-") +hello- +``` + ## Related Functions * [`trim`](/terraform/language/functions/trim) removes characters at the start and end of a string.