Thursday, December 5, 2024
HomeGolangString to uppercase in Go (Golang)

String to uppercase in Go (Golang)



To transform a string to uppercase in Go, use the strings.ToUpper() operate. It returns a replica of the enter string, through which all letters are uppercase. The operate is a part of the built-in strings package deal used for manipulating UTF-8 encoded strings.

package deal fundamental

import (
    "fmt"
    "strings"
)

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

Output:

If you wish to uppercase solely the primary letter of every phrase, see our different instance right here.

In case your string is in a language with the particular casing guidelines, for instance, Turkish or Azeri, use the strings.ToUpperSpecial() operate. This operate takes a case mapping as its first parameter, with which it converts the string into uppercase.

package deal fundamental

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

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

Output

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments