OneBite.Dev - Coding blog in a bite size

convert a string to uppercase in Go

Code snippet on how to convert a string to uppercase in Go

  package main

import (
         "fmt"
         "strings"
)

func main() {
     str := "Hello World!"

     fmt.Println(strings.ToUpper(str))
}

This code snippet uses the package main and imports two dependencies known as fmt and strings. Next, the str variable is declared and assigned the string “Hello World!” in lower case. Then, the strings package is used to call the ToUpper method, which takes the str string and the output is printed on the screen with upper case. The main function is required to execute logic and is the entry point to the program. As a result, when running this program, the output should show “HELLO WORLD!” on the screen.

go