Skip to content

Instantly share code, notes, and snippets.

@cgrady357
Created September 25, 2015 21:31
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 cgrady357/13a3154b9b8b33337be7 to your computer and use it in GitHub Desktop.
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.
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