×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang bytes.Title() Function with Examples

Golang | bytes.Title() Function: Here, we are going to learn about the Title() function of the bytes package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 26, 2021

bytes.Title()

The Title() function is an inbuilt function of the bytes package which is used to get a copy with all Unicode letters of the byte slice (s) that begin words mapped to their title case.

It accepts one parameter (s []byte) and returns a copy with all Unicode letters that begin words mapped to their title case.

Syntax

func Title(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.Title() function is a []byte, it returns a copy with all Unicode letters that begin words mapped to their title case.

Example 1

// Golang program to demonstrate the
// example of bytes.Title() function

package main

import (
	"bytes"
	"fmt"
)

func main() {
	fmt.Printf("%s\n",
		bytes.Title([]byte("Every moment is a fresh beginning.")))
	fmt.Printf("%s\n",
		bytes.Title([]byte("What we think, we become.")))
	fmt.Printf("%s\n",
		bytes.Title([]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.Title() function

package main

import (
	"bytes"
	"fmt"
)

func main() {
	var str []byte
	var result []byte

	str = []byte("Every moment is a fresh beginning.")
	result = bytes.Title(str)
	fmt.Printf("Original string: %s\n", str)
	fmt.Printf("Title case string: %s\n", result)
	fmt.Println()

	str = []byte("What we think, we become.")
	result = bytes.Title(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.Title(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: What we think, we become.
Title case string: What We Think, We Become.

Original string: Be so good they can't ignore you.
Title case string: Be So Good They Can'T Ignore You.

Golang bytes Package »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.