VB.Net convert string to title case

Our advice is to create an extension, so you can directly use the new function on strings:

Public Module MyExtensions

    <System.Runtime.CompilerServices.Extension()>
    Public Function ToTitleCase(mystring As String) As String
        Return System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(mystring)
    End Function

End Module

Now you can convert a string to tile case like this:

Dim mystring = "dotmaui is awesome!"
Dim newstring = mystring.ToTitleCase()

Response.Write(newstring)

' Result: "Dotmaui Is Awesome!"

Leave a Comment

Your email address will not be published. Required fields are marked *