TextInfo. Sometimes we want to convert a string to lowercase, uppercase, or mixed case (title case). It is possible to use the ToLower and ToUpper methods on the String type.
But with TextInfo, we have access to ToLower, ToUpper and another method called ToTitleCase. We can convert a string to title case—where each letter following a space is uppercased.
An example. To begin, we acquire an instance of the TextInfo class. We get it through CultureInfo.InvariantCulture—the invariant part just means it won't change based on the system set up.
Note With ToLower, we have the same effect as the string ToLower method—uppercase chars are converted to lowercase ones.
Note 2 With ToUpper, we convert all lowercase chars to uppercase. Nothing else happens to the string.
Finally The ToTitleCase function converts each lowercase letter that follows a space to an uppercase letter.
Imports System.Globalization
Module Module1
Sub Main()
' Get instance of TextInfo.
Dim info1 As TextInfo = CultureInfo.InvariantCulture.TextInfo
' Convert string to lowercase with TextInfo.
Dim result1 As String = info1.ToLower("BIRD")
Console.WriteLine("TOLOWER: " + result1)
' Convert to uppercase.
Dim result2 As String = info1.ToUpper("bird")
Console.WriteLine("TO UPPER: " + result2)
' Convert to title case.
Dim result3 As String = info1.ToTitleCase("blue bird")
Console.WriteLine("TO TITLE CASE: " + result3)
End Sub
End ModuleTOLOWER: bird
TO UPPER: BIRD
TO TITLE CASE: Blue Bird
Some notes. For simple calls to ToLower and ToUpper, it is better to just use the String methods. These are used more often, and are easier to understand for other developers.
A summary. The ToTitleCase method is effective in converting a string into Title Case. For many simple applications, it is a better choice than a complex method that tests each char.
Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
This page was last updated on Aug 29, 2023 (edit).