×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang bytes.ToUpperSpecial() Function with Examples

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

bytes.ToUpperSpecial()

The ToUpperSpecial() 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 upper 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 upper case.

Syntax

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

Parameters

  • c : Space case.
  • s : The byte slice to be used to create a copy of the uppercase byte slice.

Return Value

The return type of the bytes.ToUpperSpecial() function is a []byte, it returns a copy with all the Unicode letters mapped to their upper case.

Example 1

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

package main

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

func main() {
	fmt.Printf("%s\n", bytes.ToUpperSpecial(
		unicode.AzeriCase, []byte("Every moment is a fresh beginning.")))
	fmt.Printf("%s\n", bytes.ToUpperSpecial(
		unicode.AzeriCase, []byte("merhaba dünya, nasılsın?")))
	fmt.Printf("%s\n", bytes.ToUpperSpecial(
		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.ToUpperSpecial() 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.ToUpperSpecial(unicode.AzeriCase, str)
	fmt.Printf("Original string: %s\n", str)
	fmt.Printf("Uppercase string: %s\n", result)
	fmt.Println()

	str = []byte("merhaba dünya, nasılsın?")
	result = bytes.ToUpperSpecial(unicode.AzeriCase, str)
	fmt.Printf("Original string: %s\n", str)
	fmt.Printf("Uppercase string: %s\n", result)
	fmt.Println()

	str = []byte("Be so good they can't ignore you.")
	result = bytes.ToUpperSpecial(unicode.AzeriCase, str)
	fmt.Printf("Original string: %s\n", str)
	fmt.Printf("Uppercase string: %s\n", result)
}

Output:

Original string: Every moment is a fresh beginning.
Uppercase string: EVERY MOMENT İS A FRESH BEGİNNİNG.

Original string: merhaba dünya, nasılsın?
Uppercase string: MERHABA DÜNYA, NASILSIN?

Original string: Be so good they can't ignore you.
Uppercase 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.