Home »
Golang »
Golang Reference
Golang bytes.ToTitle() Function with Examples
Golang | bytes.ToTitle() Function: Here, we are going to learn about the ToTitle() function of the bytes package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 26, 2021
bytes.ToTitle()
The ToTitle() function is an inbuilt function of the bytes package which is used to get a copy of the byte slice (s – treated as UTF-8-encoded bytes) with all the Unicode letters mapped to their title case.
It accepts one parameter (s []byte) and returns a copy with all the Unicode letters mapped to their title case.
Syntax
func ToTitle(s []byte) []byte
Parameters
- s : The byte slice to be used to create a copy of the title case byte slice.
Return Value
The return type of the bytes.ToTitle() function is a []byte, it returns a copy with all the Unicode letters mapped to their title case.
Example 1
// Golang program to demonstrate the
// example of bytes.ToTitle() function
package main
import (
"bytes"
"fmt"
)
func main() {
fmt.Printf("%s\n",
bytes.ToTitle([]byte("Every moment is a fresh beginning.")))
fmt.Printf("%s\n",
bytes.ToTitle([]byte("merhaba dünya, nasılsın?")))
fmt.Printf("%s\n",
bytes.ToTitle([]byte("Be so good they can't ignore you.")))
}
Output:
EVERY MOMENT IS A FRESH BEGINNING.
MERHABA DÜNYA, NASILSIN?
BE SO GOOD THEY CAN'T IGNORE YOU.
Example 2
// Golang program to demonstrate the
// example of bytes.ToTitle() function
package main
import (
"bytes"
"fmt"
)
func main() {
var str []byte
var result []byte
str = []byte("Every moment is a fresh beginning.")
result = bytes.ToTitle(str)
fmt.Printf("Original string: %s\n", str)
fmt.Printf("Title case string: %s\n", result)
fmt.Println()
str = []byte("merhaba dünya, nasılsın?")
result = bytes.ToTitle(str)
fmt.Printf("Original string: %s\n", str)
fmt.Printf("Title case string: %s\n", result)
fmt.Println()
str = []byte("Be so good they can't ignore you.")
result = bytes.ToTitle(str)
fmt.Printf("Original string: %s\n", str)
fmt.Printf("Title case string: %s\n", result)
}
Output:
Original string: Every moment is a fresh beginning.
Title case string: EVERY MOMENT IS A FRESH BEGINNING.
Original string: merhaba dünya, nasılsın?
Title case string: MERHABA DÜNYA, NASILSIN?
Original string: Be so good they can't ignore you.
Title case string: BE SO GOOD THEY CAN'T IGNORE YOU.
Golang bytes Package »