In Golang, you can convert a string to uppercase by using the strings
package and the ToUpper
function.
Here's an example:
package main
import (
"fmt"
"strings"
)
func main() {
str := "hello world"
str = strings.ToUpper(str)
fmt.Println(str)
}
Output:
HELLO WORLD
In this example, we import the strings
package and use the ToUpper
function to convert the string variable str
to uppercase. The ToUpper
function returns a new string that contains the uppercase version of the input string, so we assign this new value back to the str
variable. Finally, we print the uppercase string to the console.