Cookies management by TermsFeed Cookie Consent

πŸ”  String to uppercase in Go

shorts strings

To convert a string to uppercase in Go, use the strings.ToUpper() function. It returns a copy of the input string, in which all letters are uppercase. The function is part of the built-in strings package used for manipulating UTF-8 encoded strings.

package main

import (
    "fmt"
    "strings"
)

func main() {
    fmt.Println(strings.ToUpper("https://gosamples.dev"))
}

Output:

HTTPS://GOSAMPLES.DEV

If you want to uppercase only the first letter of each word, see our other example here.

If your string is in a language with the special casing rules, for example, Turkish or Azeri, use the strings.ToUpperSpecial() function. This function takes a case mapping as its first parameter, with which it converts the string into uppercase.

package main

import (
    "fmt"
    "strings"
    "unicode"
)

func main() {
    fmt.Println(strings.ToUpperSpecial(unicode.TurkishCase, "en iyi web sitesi"))
}

Output

EN Δ°YΔ° WEB SΔ°TESΔ°

Thank you for being on our site 😊. If you like our tutorials and examples, please consider supporting us with a cup of coffee and we'll turn it into more great Go examples.

Have a great day!

Buy Me A Coffee

🐾 How to compare strings in Go

shorts introduction strings

πŸ” Repeat a string in Go

shorts strings

πŸ₯‡ How to uppercase the first letter of each word in Go

shorts strings