Golang String to Uppercase

To convert string to upper case in Go programming, call strings.ToUpper() function and pass the string as argument to this function.

In this tutorial, we will learn how to transform a string to upper case using strings.ToLower() function.

Syntax

The syntax of ToUpper() function is

</>
Copy
 strings.ToUpper(str)

where

  1. strings is the package.
  2. ToUpper is the function name.
  3. str is the input string.

strings.ToLower() function returns string with all characters in the original string converted to upper case alphabets.

Example

In the following program, we will take a string str containing a mix of lower and upper case alphabets and convert it to upper case.

example.go

</>
Copy
package main

import (
	"fmt"
	"strings"
)

func main() {
	var str = "HelLo WoRld"
	var str_upper = strings.ToUpper(str)
	fmt.Printf(str_upper)
}

Output

HELLO WORLD

Conclusion

In this Golang Tutorial, we learned how to convert a string to upper case using strings.ToUpper() function.