Home »
Golang »
Golang Reference
Golang bytes.ToLower() Function with Examples
Golang | bytes.ToLower() Function: Here, we are going to learn about the ToLower() function of the bytes package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 26, 2021
bytes.ToLower()
The ToLower() function is an inbuilt function of the bytes package which is used to get a copy of the byte slice (s) with all Unicode letters mapped to their lower case.
It accepts one parameter (s []byte) and returns a copy of the byte slice s with all Unicode letters mapped to their lower case.
Syntax
func ToLower(s []byte) []byte
Parameters
- s : The byte slice to be used to create a copy of the lowercase byte slice.
Return Value
The return type of the bytes.ToLower() function is a []byte, it returns a copy of the byte slice s with all Unicode letters mapped to their lower case.
Example 1
// Golang program to demonstrate the
// example of bytes.ToLower() function
package main
import (
"bytes"
"fmt"
)
func main() {
fmt.Printf("%s\n",
bytes.ToLower([]byte("Every moment is a fresh beginning.")))
fmt.Printf("%s\n",
bytes.ToLower([]byte("What we think, we become.")))
fmt.Printf("%s\n",
bytes.ToLower([]byte("Be so good they can't ignore you.")))
}
Output:
every moment is a fresh beginning.
what we think, we become.
be so good they can't ignore you.
Example 2
// Golang program to demonstrate the
// example of bytes.ToLower() function
package main
import (
"bytes"
"fmt"
)
func main() {
var str []byte
var result []byte
str = []byte("Every moment is a fresh beginning.")
result = bytes.ToLower(str)
fmt.Printf("Original string: %s\n", str)
fmt.Printf("Lowercase string: %s\n", result)
fmt.Println()
str = []byte("What we think, we become.")
result = bytes.ToLower(str)
fmt.Printf("Original string: %s\n", str)
fmt.Printf("Lowercase string: %s\n", result)
fmt.Println()
str = []byte("Be so good they can't ignore you.")
result = bytes.ToLower(str)
fmt.Printf("Original string: %s\n", str)
fmt.Printf("Lowercase string: %s\n", result)
}
Output:
Original string: Every moment is a fresh beginning.
Lowercase string: every moment is a fresh beginning.
Original string: What we think, we become.
Lowercase string: what we think, we become.
Original string: Be so good they can't ignore you.
Lowercase string: be so good they can't ignore you.
Golang bytes Package »