ToUpper, ToLower, and ToTitleCase

ToUpper converts any lowercase characters in a string into uppercase. ToLower converts any uppercase characters in a string into lowercase:

'aBc'.ToUpper()    # Returns ABC 
'AbC'.ToLower()    # Returns abc 

Considering that the methods discussed here are case sensitive, converting a string into a known case may be an important first step. Consider the following example:

$string = 'AbN' 
$string = $string.ToLower() 
$string = $string.Replace('n', 'c') 

The ToTitleCase is not a method of the String object. It is a method of the System.Globalization.TextInfo class. The ToTitleCase method performs limited culture-specific capitalization of words:

PS> (Get-Culture).TextInfo.ToTitleCase('some title') 
Some Title

As this is not a static method, the TextInfo object must be created first. This object cannot be directly created. TextInfo can be obtained via the System.Globalization.CultureInfo object, and this object is returned by the Get-Culture command.

The same TextInfo object may also be accessed using the host automatic variable:

$host.CurrentCulture.TextInfo.ToTitleCase('another title') 

The ToTitleCase method will not convert words that are entirely uppercase as they're considered to be acronyms.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.21.109