Golang unicode.ToLower() Function with Examples

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

unicode.ToLower()

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

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

Syntax:

func ToLower(r rune) rune

Parameter(s):

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

Return Value:

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

Example 1:

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

package main

import (
	"fmt"
	"unicode"
)

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

Output:

U+0071 'q'
U+0071 'q'
U+0072 'r'
U+00E4 'ä'

Example 2:

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

package main

import (
	"fmt"
	"unicode"
)

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

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

Output:

LowerCase:
hello, world!

Golang unicode Package »




Comments and Discussions!

Load comments ↻





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