From 23fa18d177a80b3ca9e4c5a702470da5b5106f63 Mon Sep 17 00:00:00 2001 From: Richard Wilkes Date: Wed, 20 Nov 2024 16:02:18 -0800 Subject: [PATCH] Add txt.CapitalizeWords --- txt/capitalize.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 txt/capitalize.go diff --git a/txt/capitalize.go b/txt/capitalize.go new file mode 100644 index 0000000..b6880dd --- /dev/null +++ b/txt/capitalize.go @@ -0,0 +1,14 @@ +package txt + +import ( + "strings" +) + +// CapitalizeWords capitalizes the first letter of each word in a string. +func CapitalizeWords(s string) string { + words := strings.Fields(s) + for i, word := range words { + words[i] = FirstToUpper(strings.ToLower(word)) + } + return strings.Join(words, " ") +}