Skip to content

Instantly share code, notes, and snippets.

@cgrady357

cgrady357/ProperCase.ps1 Secret

Created Sep 25, 2015
Embed
What would you like to do?
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.
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