How to UpperCase a String in Golang

In Go, there are multiple ways to make a string UpperCase, each of them are by using the strings package.

Option 1 (strings.ToUpper):

func ToUpper(str string) string

package main import ( "fmt" "strings" ) func main() { str1 := "This is a Test" fmt.Println(strings.ToUpper(str1)) // "THIS IS A TEST" }
Code language: Go (go)

Option 2 (strings.ToTitle):

func ToTitle(str string) string

package main import ( "fmt" "strings" ) func main() { str1 := "This is a Test" fmt.Println(strings.ToTitle(str1)) // "THIS IS A TEST" }
Code language: Go (go)

Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments