how to convert string to uppercase in golang?
September 27, 2022Hi Friends 👋,
Welcome To aGuideHub! ❤️
To convert string to uppercase in golang, just use ToUpper()
method and pass your string, it will convert string into uppercase.
Follow the below tutorial if you are struggling with installing GO in windows.
https://aguidehub.com/blog/how-to-install-golang-in-windows/
Today, I will show you how do I convert string to uppercase in golang, as above mentioned I’m going to use ToUpper()
way.
The strings
package provide ToUpper()
method.
Let’s start our Golang convert string to uppercase example
Convert whole string into uppercase example
main.go
package main
import (
"fmt"
"strings"
)
func main() {
str1 := "aGuideHub"
str2 := "Infinitbility"
str3 := "sortoutcode"
res1 := strings.ToUpper(str1)
res2 := strings.ToUpper(str2)
res3 := strings.ToUpper(str3)
fmt.Println("Result 1:", res1)
fmt.Println("Result 2:", res2)
fmt.Println("Result 3:", res3)
}
In the above example, we have converted string to uppercase and printed in golang console. let’s check the output.
Output
Result 1: AGUIDEHUB
Result 2: INFINITBILITY
Result 3: SORTOUTCODE
I hope it helps you, All the best 👍.