ToTitleCase FunctionUse the ToTitleCase Function from System.Globalization, making each word title case.
This page was last reviewed on Sep 25, 2022.
ToTitleCase uppercases each word in a String. Custom-developed algorithms may be superior. But the ToTitleCase function from System.Globalization is more convenient.
Function notes. ToTitleCase is effective in many VB.NET programs. This example shows the ToTitleCase method on TextInfo from System.Globalization.
First, import the System.Globalization namespace. In Main, we use the TextInfo instance on CultureInfo.CurrentCulture and call ToTitleCase.
Result The output has each letter following a space or period uppercased. This is a simple example, so it works well.
Imports System.Globalization Module Module1 Sub Main() Dim value As String = "dot net perls vb.net" Dim title As String = CultureInfo.CurrentCulture. TextInfo.ToTitleCase(value) Console.WriteLine(title) End Sub End Module
Dot Net Perls Vb.Net
A warning. Unfortunately, ToTitleCase does not contain extensive logic. It cannot handle special cases. For example, the acronym "VB.NET" is not uppercased correctly.
Info To solve this problem, you can call Replace on every special case you require.
Summary. There are many ways to do the same basic tasks in the .NET Framework. ToTitleCase is built into the .NET Framework for you, but it cannot cover every possible case you might require.
Uppercase First
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Sep 25, 2022 (edit).
© 2007-2023 Sam Allen.