Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Covert a string to a title format, i.e. each word is capitalized in the first letter with rest as low-cased.
<#
.SYNOPSIS
Capitalize the first letter of each word in a string
.DESCRIPTION
Capitalize the first letter of each word in a text string, and make the rest of each word to be lower-cased
.Input
a string can be piped into this function.
.PARAMETER Text
The $Text is the string which will be converted with a capitalized initial letter.
Pipeline input is accepted
.EXAMPLE
ConvertTo-StringTitle -Text "hELLo, wOrlD !"
you will get
"Hello, World !"
.Example
"hEllo, wOrlD !" | ConvertTo-StringTitle
you will get the same as the previous example
"Hello, World !"
.Note
Sept 23, 2015 by jeffrey_yao at hotmail.com
#>
function ConvertTo-StringTitle
{
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline)]
[string]$Text=''
)
(Get-Culture).TextInfo.ToTitleCase($Text.ToLower());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment