How to convert string to uppercase in Golang
convert
string
toupper
go
golang
Here is a simple snippet of how to convert a string to uppercase using Golang. If you need help how to install Golang check the references links.
Code
To convert a string into uppercase, use the ToUpper
method from strings
package.
package main
import (
"fmt"
"strings"
)
func main() {
str := "Hello from ADMFactory.com"
res:= strings.ToUpper(str)
fmt.Println("String to Uppercase Golang example")
fmt.Println()
fmt.Println(str + " ==> " + res)
}
Compile&Run
To compile the code navigate to the file location and run the following command.
$ go build stringToUpper.go
Then depending on if you are on Linux or Windows the binary file is created.
To run the application execute the command.
Linux
$ ./stringToUpper
Windows
c:\Users\adm\go\tutorials> stringToUpper.exe
If you want to compile and run the application in one single step run the following command:
go run stringToUpper.go
Output
Will display the following output.
String to Uppercase Golang example
Hello from ADMFactory.com ==> HELLO FROM ADMFACTORY.COM