How to Map a Rune to Title Case 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 title case with the help of ToTitle() function. This function changes the case of the given rune(if the case of the rune is lower or upper) into title case and if the given rune is already present in title 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 ToTitle(r rune) rune

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Go program to illustrate how to
// map a rune to title case
package main
  
import (
    "fmt"
    "unicode"
)
  
// Main function
func main() {
  
    // Creating rune
    rune_1 := 'g'
    rune_2 := 'e'
    rune_3 := 'E'
    rune_4 := 'k'
  
    // Mapping the given rune into title case
    // Using ToTitle() function
    fmt.Printf("Result 1: %c ", unicode.ToTitle(rune_1))
    fmt.Printf("\nResult 2: %c ", unicode.ToTitle(rune_2))
    fmt.Printf("\nResult 3: %c ", unicode.ToTitle(rune_3))
    fmt.Printf("\nResult 4: %c ", unicode.ToTitle(rune_4))
    fmt.Printf("\nResult 5: %c ", unicode.ToTitle('s'))
  
}

chevron_right


Output:

Result 1: G 
Result 2: E 
Result 3: E 
Result 4: K 
Result 5: S 

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Go program to illustrate how to
// map a rune to title case
package main
  
import (
    "fmt"
    "unicode"
)
  
// Main function
func main() {
  
    // Creating rune
    rune_1 := 'r'
    rune_2 := 'U'
    rune_3 := 'n'
    rune_4 := 'E'
  
    // Mapping the given rune into title case
    // Using ToTitle() function
    fmt.Printf("Result 1: %c ", unicode.ToTitle(rune_1))
    fmt.Printf("\nResult 2: %c ", unicode.ToTitle(rune_2))
    fmt.Printf("\nResult 3: %c ", unicode.ToTitle(rune_3))
    fmt.Printf("\nResult 4: %c ", unicode.ToTitle(rune_4))    
  
}

chevron_right


Output:

Result 1: R 
Result 2: U 
Result 3: N 
Result 4: E 


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.