String casing

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()


PS> 'AAA'.ToLower()


Alternatively you can use the culture information

PS> (Get-Culture).TextInfo.ToLower('AAA')


PS> (Get-Culture).TextInfo.ToUpper('aaa')


PS> (Get-Culture).TextInfo.ToTitleCase('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')


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

This entry was posted in Powershell. Bookmark the permalink.

One Response to String casing

  1. cavallogolooso says:

    there are plenty of interesting methods for strings: I simply “browsed” them: very useful hint! 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s