How to Map a Rune to Lowercase in Golang?
Rune is a superset of ASCII or it is an alias of int32. It holds all the characters available in the world’s writing system, including accents and other diacritical marks, control codes like tab and carriage return, and assigns each one a standard number. This standard number is known as a Unicode code point or rune in the Go language.
You are allowed to map the given rune into the lower case with the help of ToLower() function. This function changes the case of the given rune(if the case of the rune is upper or title) into lower case and if the given rune is already present in lower case, then this function does nothing. This function is defined under Unicode package, so for accessing this method you need to import the Unicode package in your program.
Syntax:
func ToLower(r rune) rune
Example 1:
package main
import (
"fmt"
"unicode"
)
func main() {
rune_1 := 'G'
rune_2 := 'e'
rune_3 := 'E'
rune_4 := 'k'
rune_5 := 's'
fmt.Printf( "Result 1: %c " , unicode.ToLower(rune_1))
fmt.Printf( "\nResult 2: %c " , unicode.ToLower(rune_2))
fmt.Printf( "\nResult 3: %c " , unicode.ToLower(rune_3))
fmt.Printf( "\nResult 4: %c " , unicode.ToLower(rune_4))
fmt.Printf( "\nResult 5: %c " , unicode.ToLower(rune_5))
}
|
Output:
Result 1: g
Result 2: e
Result 3: e
Result 4: k
Result 5: s
Result 6: f
Example 2:
package main
import (
"fmt"
"unicode"
)
func main() {
rune_1 := 'S'
rune_2 := 'a'
rune_3 := 'M'
rune_4 := 'P'
rune_5 := 'L'
rune_6 := 'e'
fmt.Printf( "Result 1: %c " , unicode.ToLower(rune_1))
fmt.Printf( "\nResult 2: %c " , unicode.ToLower(rune_2))
fmt.Printf( "\nResult 3: %c " , unicode.ToLower(rune_3))
fmt.Printf( "\nResult 4: %c " , unicode.ToLower(rune_4))
fmt.Printf( "\nResult 5: %c " , unicode.ToLower(rune_5))
fmt.Printf( "\nResult 6: %c " , unicode.ToLower(rune_6))
}
|
Output:
Result 1: s
Result 2: a
Result 3: m
Result 4: p
Result 5: l
Result 6: e
Last Updated :
27 Sep, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...