×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang unicode.ToUpper() Function with Examples

Golang | unicode.ToUpper() Function: Here, we are going to learn about the ToUpper() function of the unicode package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 18, 2021

unicode.ToUpper()

The ToUpper() function is an inbuilt function of the unicode package which is used to map the given rune r to uppercase i.e., the ToUpper() function converts the given rune value to uppercase.

It accepts one parameter (r rune) and returns the value mapped to uppercase.

Syntax

func ToUpper(r rune) rune

Parameters

  • r : Rune type value to be mapped to uppercase.

Return Value

The return type of the unicode.ToUpper() function is a rune, it returns the value mapped to uppercase.

Example 1

// Golang program to demonstrate the
// example of unicode.ToUpper() Function

package main

import (
	"fmt"
	"unicode"
)

func main() {
	fmt.Printf("%#U\n", unicode.ToUpper('z'))
	fmt.Printf("%#U\n", unicode.ToUpper('q'))
	fmt.Printf("%#U\n", unicode.ToUpper('R'))
	fmt.Printf("%#U\n", unicode.ToUpper('Ä'))
}

Output:

U+005A 'Z'
U+0051 'Q'
U+0052 'R'
U+00C4 'Ä'

Example 2

// Golang program to demonstrate the
// example of unicode.ToUpper() Function

package main

import (
	"fmt"
	"unicode"
)

func main() {
	// constant with mixed type runes
	const mixed = "Hello, world!"

	fmt.Println("UpperCase:")
	for _, c := range mixed {
		fmt.Printf("%c", unicode.ToUpper(c))
	}
}

Output:

UpperCase:
HELLO, WORLD!

Golang unicode Package »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.