I am trying to write a function manually that capitalises the first letter of each word in a string. For example: "My dog is cute! I+love+my+dog+4ever" to "My Dog Is Cute! I+Love+My+Dog+4ever". I would be glad if you can help me.
func Capitalize(s string) string {
L := ToLower(s)
runeL := []rune(L)
len := len(runeL) - 1
Lnew := Concat(ToUpper(string(L[0])), string(runeL[1:len]))
LnewS := []rune(Lnew)
newstrings := []rune{}
for i := range LnewS {
if IsAlpha(string(LnewS[i])) == true {
newstrings = append(newstrings, LnewS[i])
} else {
newstrings = append(newstrings, LnewS[i])
if LnewS[i+1] == rune(32) {
newstrings = append(newstrings)
}
if IsLower(string(LnewS[i+1:])) {
LnewS[i+1] = LnewS[i+1] - rune(32)
}
}
}
return string(newstrings)
}