Skip to content

Commit

Permalink
Add txt.CapitalizeWords
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwilkes committed Nov 21, 2024
1 parent a30c23e commit 23fa18d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions txt/capitalize.go
Original file line number Diff line number Diff line change
@@ -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, " ")
}

0 comments on commit 23fa18d

Please sign in to comment.