Skip to content

Instantly share code, notes, and snippets.

@jeffrey-yao
Created September 24, 2015 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffrey-yao/52822db0693c13ed680b to your computer and use it in GitHub Desktop.
Save jeffrey-yao/52822db0693c13ed680b to your computer and use it in GitHub Desktop.
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