×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang strings.Title() Function with Examples

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

strings.Title()

The Title() function is an inbuilt function of strings package which is used to get a copy of the given string with all Unicode letters that begin words mapped to their Unicode title case. It accepts a string and returns the string whose beginning words are in the Unicode title case.

Syntax

func Title(str string) string

Parameters

  • str : The string to be used to get the title case.

Return Value

The return type of Title() function is a string, it returns a copy of the given string with all Unicode letters that begin words mapped to their Unicode title case.

Example 1

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

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.Title("always deliver more than expected."))
	fmt.Println(strings.Title("Nothing will work unless you do."))
	fmt.Println(strings.Title("It's not about ideas. ..."))
	fmt.Println(strings.Title("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.Title() Function

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.Title("abc123, 123abc, abc123xyz"))
	fmt.Println(strings.Title("ABC123, 123ABC, ABC123XYZ"))
	fmt.Println(strings.Title("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.