Cookies management by TermsFeed Cookie Consent
Russia has invaded Ukraine and already killed tens of thousands of civilians, with many more raped or tortured. It's a genocide. We need your help. Let's fight back against the Russian regime.
Help Ukraine! Fight the Russian regime!

🔠 String to uppercase in Go

shorts strings

Please consider supporting us by disabling your ad blocker

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İ

🥇 How to uppercase the first letter of each word in Go

shorts strings

🧽 Remove non-alphanumeric characters from a string in Go

Learn how to remove characters that are not letters or numbers from a string
strings regex

🧊 Cube root in Go

shorts numbers math