hugo/docs/content/en/functions/strings/Trim.md
2023-10-20 09:43:56 +02:00

1.2 KiB

title linkTitle description categories keywords menu function relatedFunctions aliases
strings.Trim trim Returns a slice of a passed string with all leading and trailing characters from cutset removed.
functions
docs
parent
functions
aliases returnType signatures
title
string
strings.Trim INPUT CUTSET
strings.Chomp
strings.Trim
strings.TrimLeft
strings.TrimPrefix
strings.TrimRight
strings.TrimSuffix
/functions/trim
{{ trim "++Batman--" "+-" }} → "Batman"

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:

{{ trim .Inner }}

Instead, the following example tells trim to remove extra new lines from the content contained in the shortcode .Inner variable:

{{ trim .Inner "\n" }}

{{% note %}} Go templates also provide a simple method for trimming whitespace from either side of a Go tag by including a hyphen (-). {{% /note %}}