-
-
Save MakwaWes/769559cfb27a8e469673 to your computer and use it in GitHub Desktop.
Function to format words as UpppercaseLowerCase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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