-
-
Save jeffrey-yao/52822db0693c13ed680b to your computer and use it in GitHub Desktop.
Covert a string to a title format, i.e. each word is capitalized in the first letter with rest as low-cased.
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
<# | |
.SYNOPSIS | |
Capitalize the first letter of each word in a string | |
.DESCRIPTION | |
Capitalize the first letter of each word in a text string, and make the rest of each word to be lower-cased | |
.Input | |
a string can be piped into this function. | |
.PARAMETER Text | |
The $Text is the string which will be converted with a capitalized initial letter. | |
Pipeline input is accepted | |
.EXAMPLE | |
ConvertTo-StringTitle -Text "hELLo, wOrlD !" | |
you will get | |
"Hello, World !" | |
.Example | |
"hEllo, wOrlD !" | ConvertTo-StringTitle | |
you will get the same as the previous example | |
"Hello, World !" | |
.Note | |
Sept 23, 2015 by jeffrey_yao at hotmail.com | |
#> | |
function ConvertTo-StringTitle | |
{ | |
[CmdletBinding()] | |
param ( | |
[Parameter(ValueFromPipeline)] | |
[string]$Text='' | |
) | |
(Get-Culture).TextInfo.ToTitleCase($Text.ToLower()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment