×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang bytes.ToUpper() Function with Examples

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

bytes.ToUpper()

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

It accepts one parameter (s []byte) and returns a copy of the byte slice s with all Unicode letters mapped to their upper case.

Syntax

func ToUpper(s []byte) []byte

Parameters

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

Return Value

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

Example 1

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

package main

import (
	"bytes"
	"fmt"
)

func main() {
	fmt.Printf("%s\n",
		bytes.ToUpper([]byte("Every moment is a fresh beginning.")))
	fmt.Printf("%s\n",
		bytes.ToUpper([]byte("merhaba dünya, nasılsın?")))
	fmt.Printf("%s\n",
		bytes.ToUpper([]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.ToUpper() function

package main

import (
	"bytes"
	"fmt"
)

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

	str = []byte("Every moment is a fresh beginning.")
	result = bytes.ToUpper(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.ToUpper(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.ToUpper(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 IS A FRESH BEGINNING.

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 IGNORE YOU.

Golang bytes Package »




Comments and Discussions!

Load comments ↻





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