Converting a string to title case

Converting a string to upper or lower case is easy; you can just use the ToUpper() or ToLower() methods

VB.NET

Dim s As String = "HELLO world"
s = s.ToUpper()
s = s.ToLower()

C#

string s = "HELLO world";
s = s.ToUpper();
s = s.ToLower();

Converting to Title case (or proper case as it's sometimes called) requires a bit more effort, but fortunatly the TextInfo class can help!

VB.NET

s = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo().ToTitleCase(s)

C#

s = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo().ToTitleCase(s);

 

Custom .NET Training ASP.NET Training Silverlight Training LINQ Training IT Support