How to uppercase the first letter of each word in C# and VB.NET

To uppercase the first letter of each word in C# and VB.NET you can use the following snippet.

Sample C#

public static string ToTitleCase(string input)
{
	return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input);
}

Sample VB.NET

Public Shared Function ToTitleCase(input As String) As String
	Return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input)
End Function

Please rate this snippet

How to make a string titlecase in C# or VB.NET

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

Please rate this snippet