-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathFormat-TitleCase.ps1
67 lines (60 loc) · 2.12 KB
/
Format-TitleCase.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function Format-TitleCase {
<#
.SYNOPSIS
Get the last day of the month given the year as an integer, and the month as an integer
.DESCRIPTION
Get the last day of the month given the year as an integer, and the month as an integer
.PARAMETER String
String or string array that you want to be put into your cultures title case
.PARAMETER ToLowerFirst
Switch to first put the string to lower case then put to title case
.PARAMETER IncludeInput
Switch to include the input in the output
.EXAMPLE
Format-TitleCase -String 'hello THERE'
Hello THERE
.EXAMPLE
Format-TitleCase -String 'hello THERE' -ToLowerFirst
Hello There
.EXAMPLE
Format-TitleCase -String 'hello THERE' -ToLowerFirst -IncludeInput
Original ToLowerFirst TitleCase
-------- ------------ ---------
hello THERE True Hello There
.NOTES
Inspired by: https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/title-casing-strings-capital-letter-starts-each-word
#>
[cmdletbinding()]
[OutputType('string')]
param(
[parameter(Mandatory, HelpMessage = 'Please enter a string that you want to put in Title Case', ValueFromPipeline, ValueFromPipelineByPropertyName)]
[string[]] $String,
[switch] $ToLowerFirst,
[switch] $IncludeInput
)
begin {
Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]"
$TextInfo = (Get-Culture).TextInfo
}
process {
foreach ($curString in $String) {
if ($ToLowerFirst) {
$ReturnVal = $TextInfo.ToTitleCase($curString.ToLower())
} else {
$ReturnVal = $TextInfo.ToTitleCase($curString)
}
if ($IncludeInput) {
New-Object -TypeName psobject -Property ([ordered] @{
Original = $curString
ToLowerFirst = $ToLowerFirst
TitleCase = $ReturnVal
})
} else {
Write-Output -InputObject $ReturnVal
}
}
}
end {
Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]"
}
}