From 0f3e41873605a71435c1b45ffc737c4220714a08 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Thu, 28 Mar 2024 03:34:53 +0100 Subject: [PATCH] useful string manipulation functions get text after dash, get first line and get requested by --- bot.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bot.go b/bot.go index 31717cf..d4b4292 100644 --- a/bot.go +++ b/bot.go @@ -445,3 +445,25 @@ func replaceAllStrings(str string, old []string, new string) string { return str } + +func getTextAfterDash(s string) string { + dashIndex := strings.Index(s, "-") + if dashIndex != -1 { + return strings.TrimSpace(s[dashIndex+1:]) + } + return "" +} + +func getFirstLine(s string) string { + lines := strings.SplitN(s, "\n", 2) + return lines[0] +} + +func getRequestedBy(s string) string { + re := regexp.MustCompile(`(?i)Requested By:\s*(.*)`) + match := re.FindStringSubmatch(s) + if len(match) > 1 { + return strings.TrimSpace(match[1]) + } + return "???" +} -- 2.30.2