Golang provides a ToUpper() function that converts strings into uppercase. For example if you pass a string that contains lower alphabets “abc” into
ToUpper() function then you will get alphabets in uppercase (“ABC”) in the response.
You need to import the strings package into your go file for using the ToUpper() function. So add below script in the file to import strings package.
import ( "fmt" "strings" )
This script imports fmt and strings packages.
fmt.Println(strings.ToUpper("programming")) // Output: PROGRAMMING
In this example, we passed a string into the ToUpper() function that converted the programming word into uppercase.
In the above example, we passed a single word. Now let’s pass a phrase to check if a function works with a phrase or not.
fmt.Println(strings.ToUpper("programming is easy")) // Output: PROGRAMMING IS EASY
As you can see we got uppercase based strings in the response. It means the
ToUpper() function works with both a single word and phrase.
This article demonstrates how you can convert strings in uppercase. To do that it uses the
ToUpper() function from the strings package.