Quick tip: Convert to Title Case

Most people know how to convert a string to all upper case or all lower case. In this quick tip, I’ll show you how to use ‘TextInfo’ to convert a string to Title Case.

$string = 'test string'
[System.Threading.Thread]::CurrentThread.CurrentCulture.TextInfo.ToTitleCase($string)

As you see if you test it out your self, it will output ‘Test String’. The ToTitleCase method will capitalize all words in the string.

If, on the other hand, you would like to only capitalize the first word in a sentence, the following small function might come in handy:

2 comments

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s