Skip to content

Use the title case built-in method #373

@brunodam

Description

@brunodam

Also, it is probably better to use the title case built-in method:

package main

import (
	"fmt"
	"golang.org/x/text/cases"
	"golang.org/x/text/language"
)

func main() {
	text := "welcome to the dollhouse!"
	// Create a Caser object for the desired language (Und for undefined/generic language)
	// and use its String() method to transform the text.
	// cases.Title also lowercases the remaining letters by default.
	titleCased := cases.Title(language.Und).String(text)
	fmt.Println(titleCased) // Output: Welcome To The Dollhouse!
}

Originally posted by @nathanklick in #371 (comment)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions