×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang bytes.ToTitleSpecial() Function with Examples

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

bytes.ToTitleSpecial()

The ToTitleSpecial() 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, giving priority to the special casing rules.

It accepts two parameters (c unicode.SpecialCase, s []byte) and returns a copy with all the Unicode letters mapped to their title case.

Syntax

func ToTitleSpecial(c unicode.SpecialCase, s []byte) []byte

Parameters

  • c : Special case.
  • 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.ToTitleSpecial() 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.ToTitleSpecial() function

package main

import (
	"bytes"
	"fmt"
	"unicode"
)

func main() {
	fmt.Printf("%s\n", bytes.ToTitleSpecial(
		unicode.AzeriCase, []byte("Every moment is a fresh beginning.")))
	fmt.Printf("%s\n", bytes.ToTitleSpecial(
		unicode.AzeriCase, []byte("merhaba dünya, nasılsın?")))
	fmt.Printf("%s\n", bytes.ToTitleSpecial(
		unicode.AzeriCase, []byte("Be so good they can't ignore you.")))
}

Output:

EVERY MOMENT İS A FRESH BEGİNNİNG.
MERHABA DÜNYA, NASILSIN?
BE SO GOOD THEY CAN'T İGNORE YOU.

Example 2

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

package main

import (
	"bytes"
	"fmt"
	"unicode"
)

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

	str = []byte("Every moment is a fresh beginning.")
	result = bytes.ToTitleSpecial(unicode.AzeriCase, 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.ToTitleSpecial(unicode.AzeriCase, 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.ToTitleSpecial(unicode.AzeriCase, 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 İS A FRESH BEGİNNİNG.

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 İGNORE YOU.

Golang bytes Package »




Comments and Discussions!

Load comments ↻





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