Golang bytes.ToTitle() function example

package bytes

ToTitle returns a copy of the byte input slice with all Unicode letters mapped to their title case.

Golang bytes.ToTitle() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {
 str := []byte("this is a title!")

 title := bytes.Title(str)  // for comparison purpose
 totitle := bytes.ToTitle(str) 


 fmt.Println("Original : " + string(str))
 fmt.Println("Title : " + string(title))
 fmt.Println("To Title : " + string(totitle))
 }

Output :

Original : this is a title!

Title : This Is A Title!

To Title : THIS IS A TITLE!

Advertisement