How to Map a Rune to Lowercase in Golang?


In Go, runes are used to represent Unicode code points, and they are often used in text processing applications. In some cases, you may need to convert a rune to its lowercase representation. In this article, we will discuss how to map a rune to lowercase in Go.

Mapping a Rune to Lowercase in Go

In Go, you can use the unicode.ToLower() function to convert a rune to its lowercase representation. The ToLower() function takes a single parameter, which is the rune that you want to convert to lowercase, and returns the lowercase version of the rune.

Example

Here is an example that demonstrates how to use unicode.ToLower() to convert a rune to its lowercase representation −

package main

import (
   "fmt"
   "unicode"
)

func main() {
   r := 'A'
   rLower := unicode.ToLower(r)
   fmt.Printf("Original Rune: %c\n", r)
   fmt.Printf("Lowercase Rune: %c\n", rLower)
}

In this example, we define a rune r with the value 'A'. We use the unicode.ToLower() function to convert r to its lowercase representation, and assign the result to a new variable rLower. Finally, we print the original rune and the lowercase version of the rune using fmt.Printf().

Output

The output of this program will be −

Original Rune: A
Lowercase Rune: a

Conclusion

In this article, we discussed how to map a rune to lowercase in Go using the unicode.ToLower() function. The ToLower() function allows you to convert a single rune to its lowercase representation. We also provided an example that demonstrated how to use unicode.ToLower() to convert the rune 'A' to its lowercase representation. By following the guidelines outlined in this article, you should be able to map runes to lowercase in your Go programs.

Updated on: 08-May-2023

361 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements