Skip to content

Instantly share code, notes, and snippets.

/Format-TitleCase Secret

Created Sep 24, 2015
Embed
What would you like to do?
Windows PowerShell TFM Book Contest and Giveaway
function Format-TitleCase {
<#
.SYNOPSIS
Takes a string of text in any case and formats it to the first letter in every word as capital.
.DESCRIPTION
Format-TitleCase is a function that changes a strin of test to capitalize the first letter in every word,
ignoring special characters and numbers.
.PARAMETER Words
String of text to format.
.EXAMPLE
Format-TitleCase 'StrIng oF teXT'
'StrIng oF teXT' | Format-TitleCase
.NOTES
Created John Raley
#>
[CmdletBinding()]
param (
[Parameter(Mandatory,
ValueFromPipeline)]
[String]$words
)
process {
$TextInfo = (Get-Culture).TextInfo
$TextInfo.ToTitleCase($words.ToLower())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment