×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang unicode.ToTitle() Function with Examples

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

unicode.ToTitle()

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

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

Syntax

func ToTitle(r rune) rune

Parameters

  • r : Rune type value to be mapped to title case.

Return Value

The return type of the unicode.ToTitle() function is a rune, it returns the value mapped to the title case.

Example 1

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

package main

import (
	"fmt"
	"unicode"
)

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

Output:

U+0051 'Q'
U+0051 'Q'
U+0052 'R'
U+00C4 'Ä'

Example 2

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

package main

import (
	"fmt"
	"unicode"
)

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

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

Output:

TitleCase:
HELLO, WORLD!

Golang unicode Package »




Comments and Discussions!

Load comments ↻





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