-
-
Save cgrady357/13a3154b9b8b33337be7 to your computer and use it in GitHub Desktop.
ProperCase PowerShell Function - Accepts a string and converts first character of each word to uppercase and converts the rest of the characters in the word to lowercase.
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 ProperCase { | |
<# | |
.NAME | |
ProperCase | |
.DESCRIPTION | |
Accepts a string and converts first character of each word to uppercase and converts the rest of the characters in the word to lowercase. | |
.PARAMETER StringToModify | |
String to modify | |
.NOTES | |
AUTHOR....: Craig Grady | |
LAST EDIT.: 09/25/2015 | |
CREATED...: 09/25/2015 | |
#> | |
[CmdletBinding()] | |
param( | |
[Parameter( | |
Position=0, | |
#Mandatory=$true, | |
ValueFromPipeline=$true, | |
ValueFromPipelineByPropertyName=$true)] | |
[string]$StringToModify = 'ThE wINDOWS PowerShell TFM book CONTEST aND GiVeAwAY' | |
) | |
$list = New-Object -TypeName System.Collections.ArrayList | |
$StringToModify.split() | %{ $x = $_; | |
$word = New-Object -TypeName System.Collections.ArrayList | |
$null = $word.Add($x[0].ToString().ToUpper()); | |
for($loop = 1; $loop -le $x.Length -1; $loop++) | |
{ $null = $word.Add($x[$loop].ToString().ToLower()) } | |
$null = $list.Add(-join $word) | |
} | |
$list -join " " | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment