From 0c6ec1cd021796398f8416a7729fbdcef40a2be8 Mon Sep 17 00:00:00 2001 From: kai Date: Wed, 8 Nov 2023 13:10:41 +0000 Subject: [PATCH] Add `TrimBlankLine` function. Closes #79 --- helpers/string.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/helpers/string.go b/helpers/string.go index d621bdd..26ae4a5 100644 --- a/helpers/string.go +++ b/helpers/string.go @@ -133,3 +133,10 @@ func PadRight(str string, length int, pad byte) string { } return buf.String() } + +// TrimBlankLines removes any empty lines from the string +func TrimBlankLines(str string) string { + lines := strings.Split(str, "\n") + strippedLines := RemoveFromStringSlice(lines, "") + return strings.Join(strippedLines, "\n") +}