how to convert string to uppercase in golang?

Hi 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

Try it Yourself

I hope it helps you, All the best 👍.

Premium Content

You can get all the below premium content directly in your mail when you subscribe us

Books

Interview Questions

Soon You will get CSS, JavaScript, React Js, and TypeScript So Subscribe to it.

Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

Related Posts