How do I remove x characters from a string?

I have variables/strings in the following format with the variable name Zeitraum_Begin

2019-05-01

I want to remove the last six characters to show only the year.

2019

I use {{ .Zeitraum_Begin | truncate 4 }}

But it put out 2019 … which is correct.

Is there a filter to remove x characters from a string? I haven’t found a filter for that.

If you store them in your data files/front matter without quotes, you could use date formatting to get to where you want.

If it’s a string, see https://gohugo.io/functions/substr/#readout

Hey @bep thank you for your answer! So there is no truncate version without the …, right?

I will try the date-version. Thank you for the link!

It would be a good idea to link the https://gohugo.io/functions/substr/ page on https://gohugo.io/functions/truncate/ › That’s where I searched first for a similiar function!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.