×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang strings.ToUpper() Function with Examples

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

strings.ToUpper()

The ToUpper() function is an inbuilt function of strings package which is used to get a copy of the string with all Unicode letters mapped to their upper case. It accepts a string and returns the string with all Unicode letters mapped to their upper case.

Syntax

func ToUpper(str string) string

Parameters

  • str : The string to be used to get the uppercase.

Return Value

The return type of ToUpper() function is a string, it returns a copy of the string with all Unicode letters mapped to their upper case.

Example 1

// Golang program to demonstrate the
// example of strings.ToUpper() Function

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.ToUpper("always deliver more than expected."))
	fmt.Println(strings.ToUpper("Nothing will work unless you do."))
	fmt.Println(strings.ToUpper("It's not about ideas. ..."))
	fmt.Println(strings.ToUpper("what would you do if you were not afraid?"))
}

Output:

ALWAYS DELIVER MORE THAN EXPECTED.
NOTHING WILL WORK UNLESS YOU DO.
IT'S NOT ABOUT IDEAS. ...
WHAT WOULD YOU DO IF YOU WERE NOT AFRAID?

Example 2

// Golang program to demonstrate the
// example of strings.ToUpper() Function

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.ToUpper("abc123, 123abc, abc123xyz"))
	fmt.Println(strings.ToUpper("ABC123, 123ABC, ABC123XYZ"))
	fmt.Println(strings.ToUpper("okay@123! OKAY@123! 123!@okay"))
}

Output:

ABC123, 123ABC, ABC123XYZ
ABC123, 123ABC, ABC123XYZ
OKAY@123! OKAY@123! 123!@OKAY

Golang strings Package Functions »




Comments and Discussions!

Load comments ↻





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