-
-
Save p0w3rsh3ll/6732ac0e8706cc9aaa40 to your computer and use it in GitHub Desktop.
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
#Requires -Version 3.0 | |
Function ConvertTo-NicelyFormattedString { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory,ValueFromPipeline)] | |
[string[]]$InputObject | |
) | |
Begin {} | |
Process { | |
$results = @() | |
$InputObject | ForEach-Object { | |
$_ -split '\s{1,}' | ForEach-Object { | |
$allLetters = $_.ToCharArray() | |
$FirstLetter = ($allLetters[0]).ToString().ToUpper() | |
if ($allLetters.Count -gt 1) { | |
$RemainingLetters = (-join ($allLetters[1.. ($allLetters.Count-1)])).toLower() | |
} else { | |
$RemainingLetters = [string]::Empty | |
} | |
$results += '{0}{1}' -f $FirstLetter,$RemainingLetters | |
} | |
} | |
$results -join ' ' | |
} | |
End {} | |
<# | |
.SYNOPSIS | |
First letter to upper case and remaining to lower case | |
.DESCRIPTION | |
It will capitalize the first letter of each word in a string of text and convert the remaining letters in each word to lower case. | |
If the word is a single character, it will be converted to upper case. | |
.PARAMETER InputObject | |
InputObject is an array of string and each string can have more than one word. | |
.EXAMPLE | |
ConvertTo-NicelyFormattedString 'ThE wINDOWS PowerShell TFM book CONTEST aND GiVeAwAy' | |
.EXAMPLE | |
'ThE wINDOWS PowerShell TFM is a b1ook CONTEST aND GiVeAwAy', | |
'ThE wINDOWS PowerShell TFM iS A b2ook CONTEST aND GiVeAwAy', | |
'ThE wINDOWS PowerShell TFM is a b3ook CONTEST aND GiVeAwAy' | ConvertTo-NicelyFormattedString | |
.LINK | |
http://mikefrobbins.com/2015/09/23/windows-powershell-tfm-book-contest-and-giveaway/ | |
#> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment