To make a string titlecase in C# or VB.NET you can use the following snippet.

Sample C#

public string TitleCase(string input)
{
    if (mText == null) 
	{
		return input;
	}
    System.Globalization.CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
    System.Globalization.TextInfo textInfo = cultureInfo.TextInfo;
    return textInfo.ToTitleCase(input.ToLower());
}

Sample VB.NET

Public Function TitleCase(input As String) As String
	If mText Is Nothing Then
		Return input
	End If
	Dim cultureInfo As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
	Dim textInfo As System.Globalization.TextInfo = cultureInfo.TextInfo
	Return textInfo.ToTitleCase(input.ToLower())
End Function

One thought on “How to make a string titlecase in C# or VB.NET”

Leave a Reply