PowerShell for Windows Admins

May 30 2017   1:55PM GMT

String casing

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Tags:
Powershell

There are times when you may want to change string casing. You have a couple of options.

There are a couple of methods on the string class that you can use to modify the case of a string.

PS> 'aaa'.ToUpper()
AAA

PS> 'AAA'.ToLower()
aaa

Alternatively you can use the culture information

PS> (Get-Culture).TextInfo.ToLower('AAA')
aaa
 PS> (Get-Culture).TextInfo.ToUpper('aaa')
 AAA
 PS> (Get-Culture).TextInfo.ToTitleCase('aaa')
Aaa

The interesting one is To Titlecase which will capitalise the first letter and make the rest lower case

PS> (Get-Culture).TextInfo.ToTitleCase('aaBaaC')
Aabaac

At least it does for my culture settings

PS> Get-Culture

LCID             Name             DisplayName
 ----             ----             -----------
 2057             en-GB            English (United Kingdom)

You’ll need to test what it does if you have a different culture setting

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: