Skip to content

Instantly share code, notes, and snippets.

@MakwaWes
Created September 24, 2015 12:33
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 MakwaWes/769559cfb27a8e469673 to your computer and use it in GitHub Desktop.
Save MakwaWes/769559cfb27a8e469673 to your computer and use it in GitHub Desktop.
Function to format words as UpppercaseLowerCase
Function Format-WordCase {
<#
.Synopsis
Formats a string as uppercase first letter of each word
.DESCRIPTION
The function will take any string and parses each word in order to apply an uppercase first letter and then lowercase every other letter of the word.
.EXAMPLE
Format-WordCase -String "MY STRING has NO SPEcfic case HeRe"
This cmdlet will output "My String Has No Specfic Case Here".
.Example
"MY STRING has NO SPEcfic case HeRe", "we are the champions" | Format-WordCase
Formatting words by piping directly an array.
.INPUTS
System.String
.OUTPUTS
System.String
.NOTES
Quick function for Mike F. Robbins contest
.LINK
http://mikefrobbins.com/2015/09/23/windows-powershell-tfm-book-contest-and-giveaway/
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[string[]]$String
)
Process{
$String -split " " | ForEach-Object{
$Case = $_.SubString(0,1).ToUpper()
$Case += $_.Substring(1).ToLower() + " "
Write-Verbose -Message "Modified `"$_`" to `"$Case`""
$Case
} | ForEach-Object{
$Final += $Case
Write-Verbose -Message "$Final - $Case"
}
$Final
Remove-Variable Case,Final
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment