ToTitleCase
This uppercases each word in a String
. Custom-developed algorithms may be superior. But the ToTitleCase
function from System.Globalization
is more convenient.
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
.
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 ModuleDot Net Perls Vb.Net
Unfortunately, ToTitleCase
does not contain extensive logic. It cannot handle special cases. For example, the acronym "VB.NET" is not uppercased correctly.
Replace
on every special case you require.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.