Golang Convert String to Uppercase - ToUpper() - Example

Golang Convert String to Uppercase ? ToUpper() ? Example

Golang String to Uppercase

To convert string to lowercase in Golang, you can use strings.ToUpper() function. The syntax of ToUpper() function is:

strings.ToUpper(str)

where

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

strings.ToLower() function returns string with all character converted to upper case alphabets.

In this tutorial, we will learn how to transform a string to upper case in Golang.

Golang Example to Convert String to Upper Case

In this example, we will take a string containing a mix of lower and upper case alphabets and convert it to upper case.

example.go

package main import (

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

Output

C:\workspace\go>go run example.go HELLO WORLD

Conclusion

In this Golang Tutorial, we learned how to convert a string to upper case.

Golang Golang Tutorial Run Golang Program Golang If Else Golang Switch Golang For Loop Golang Comments Golang Functions Golang Array Golang Slice Golang Struct Golang Class Golang Range Golang Map Golang Goroutine Golang Channel

Golang String Operations Golang String Length Golang String Concatenation Golang Split String Golang String - Get Index of Substr Golang String to Uppercase Golang String to Lowercase

Golang String to Lowercase Golang Convert String to Integer

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download