To convert a string to uppercase in Go, you can use the strings.ToUpper()
function from the strings package.
In this example,
str1
with a string value of "Hello World"
.strings.ToUpper()
function to convert it to uppercase and store the result in the variable upperCaseStr1
.strings.ToUpper()
function returns a new string with all characters converted to uppercase.upperCaseStr1
.package main
import (
"fmt"
"strings"
)
func main() {
str1 := "Hello World"
upperCaseStr1 := strings.ToUpper(str1)
fmt.Println("Uppercase of given string is:", upperCaseStr1)
}
Uppercase of given string is: HELLO WORLD
In this example,
str2
with a string value of "apple"
.strings.ToUpper()
function to convert it to uppercase and store the result in the variable upperCaseStr2
.strings.ToUpper()
function returns a new string with all characters converted to uppercase.upperCaseStr2
.package main
import (
"fmt"
"strings"
)
func main() {
str2 := "apple"
upperCaseStr2 := strings.ToUpper(str2)
fmt.Println("Uppercase of given string is:", upperCaseStr2)
}
Uppercase of given string is: APPLE
In this tutorial, we learned How to convert String to Uppercase in Go language with well detailed examples.