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"
}

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"
}