ADVERTISEMENT
ADVERTISEMENT

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

Parameter(s):

  • 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("[email protected]! [email protected]! [email protected]"))
}

Output:

Abc123, 123abc, Abc123xyz
ABC123, 123ABC, ABC123XYZ
[email protected]! [email protected]! [email protected]

Golang strings Package Functions »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.