ToTitleCase method in VB.NET

ToTitleCase method

The ToTitleCase method is used to convert the first character of a string to uppercase and the rest of the characters to lowercase.

CultureInfo class

The CultureInfo class provides the information about a specific culture. such as the associated language, sublanguage, country/region, calendar.

System.Globalization.CultureInfo

A neutral culture is specified by only the two-letter lowercase language code. For example, "fr" specifies the neutral culture for French.

TextInfo property

The TextInfo property defines the writing system associated with the culture.

For example

The below code defines the ToTitleCase method.

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim str As String

        Dim cultureInfo As New System.Globalization.CultureInfo("en-US")

        str = cultureInfo.TextInfo.ToTitleCase("rohatash kumar")

        MsgBox(str)

    End Sub

End Class

The above code display the following output.

Output

1.gif