How to convert strings to lowercase, uppercase, or title case using VB.NET

To convert string from lower to upper or upper to lower you should use String class to convert them.
  • 6321
 

To convert string from lower to upper or upper to lower  you  should use String class to convert them. ToLower() method change all string into lower case and  ToUpper() method change all string to upper case. These are static method of Sting class.

Syntax: String.ToLower()
Syntax: String.ToUpper()

String class does not all to convert string to title case. To convert string to title case use ToTitleCase() method in the TextInfo class.

TextInfo Class is  member of System.Globalization namespace. ToTitleCase() method is not static method. If you are using TextInfo class you must specify culture information. Culture Info class provides represent information about a specific culture and you can default to the culture that is currently in use. You can get culture information by retrieving the CurrentCulture property from current thread.

Dim CI As CultureInfo = Thread.CurrentThread.CurrentCulture
Dim TI As TextInfo = CI.TextInfotThread.CurrentCulture

Code

Imports
System.Globalization
Imports
System.Threading
Module
Module1
    Sub Main()
        Console.WriteLine("Enter any string")
        Dim str1 As String = Console.ReadLine()
        Console.WriteLine("------------")
        Console.WriteLine("Your string convert to upper case ")
        Console.WriteLine(str1.ToUpper())
        Console.WriteLine("------------")
        Console.WriteLine("Your string convert to lower case ")
        Console.WriteLine(str1.ToLower())
        Console.WriteLine()
        Console.WriteLine()
        Console.WriteLine("--------------")
        Console.WriteLine("Convert string using TextInfo Class")
        Dim cultureInfo As CultureInfo = Thread.CurrentThread.CurrentCulture
        Dim textInfo As TextInfo = cultureInfo.TextInfo
        Console.WriteLine("------------")
        Console.WriteLine("Your string convert to upper case using TextInfo Class")
        Console.WriteLine(textInfo.ToUpper(str1))
        Console.WriteLine("------------")
        Console.WriteLine("Your string convert to lower case using TextInfo Class")
        Console.WriteLine(textInfo.ToLower(str1))
        Console.WriteLine("------------")
        Console.WriteLine("Your string convert to title case using TextInfo Class")
        Console.WriteLine(textInfo.ToTitleCase(str1))
        Console.ReadLine()
    End Sub

End
Module

Output

Untitled-1.gif

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.