Proper case in vb.net
Convert a String to Uppercase
The String class has a static method named ToUpper. You can use this method to convert a string to uppercase. You can also use the UCase or StrConv function. For example:
Dim upper as String = "converted from lowercase" Console.WriteLine(upper.ToUpper()) Console.WriteLine(UCase(upper)) Console.WriteLine(StrConv(upper,VbStrConv.UpperCase))
Convert a String to Lowercase
The ToLower method is the complement of the ToUpper method. ToLower converts a string to lowercase. You can also use the LCase or StrConv function. For example:
Dim lower as String = "CONVERTED FROM UPPERCASE" Console.WriteLine(lower.ToLower()) Console.WriteLine(LCase(lower)) Console.WriteLine(StrConv(lower,VbStrConv.LowerCase))
Convert a String to Title Case
To convert a string to title (or proper) case, pass the string to the StrConv function with a constant that identifies the operation to be performed. For example:
Dim title as String = "converted to title case" Console.WriteLine(StrConv(title, VbStrConv.ProperCase))
Convert String Using the TextInfo Class
This section describes how to use the TextInfo class to convert strings. Because you can use the conversion methods inTextInfo to control culture information, you may want to use this class when you need to specify particular culture settings. TextInfo is member of the System.Globalization namespace. TextInfo provides the ToUpper, ToLower, and ToTitleCasemethods for conversion to uppercase, lowercase, and title case respectively. Unlike the methods of the String class, theTextInfo methods are not static methods and require an instance of the class. In most situations, you can default to the culture that is currently in use. Culture information is a property of the thread on which the code is running. To obtain the culture information, you must gain access to the current thread and retrieve theCurrentCulture property from that thread. Once you accomplish this, you can create the TextInfo object. For example:
Dim curCulture As CultureInfo = Thread.CurrentThread.CurrentCulture Dim tInfo As TextInfo = curCulture.TextInfo()
The following code sample illustrates how to call the three string conversion methods of the TextInfo class:
Dim title as String = "converted using textinfo" Console.WriteLine(tInfo.ToTitleCase(title)) Console.WriteLine(tInfo.ToLower(title)) Console.WriteLine(tInfo.ToUpper(title)) Example : Imports System.Globalization Imports System.Threading Module Module1 Public Sub main() Dim title As String = "this is my converted string" Console.WriteLine("Built-in Methods") Console.WriteLine("----------------") Console.WriteLine(UCase(title)) Console.WriteLine(LCase(title)) Console.WriteLine(StrConv(title, VbStrConv.UpperCase)) Console.WriteLine(StrConv(title, VbStrConv.LowerCase)) Console.WriteLine(StrConv(title, VbStrConv.ProperCase)) Console.WriteLine() Console.WriteLine("String Class") Console.WriteLine("------------") Console.WriteLine(title.ToUpper()) Console.WriteLine(title.ToLower()) Console.WriteLine() Console.WriteLine("TextInfo Class") Console.WriteLine("--------------") 'Get culture information from current thread. Dim curCulture As CultureInfo = Thread.CurrentThread.CurrentCulture 'Create TextInfo object. Dim tInfo As TextInfo = curCulture.TextInfo() 'Convert to uppercase. Console.WriteLine(tInfo.ToUpper(title)) 'Convert to lowercase. Console.WriteLine(tInfo.ToLower(title)) 'Convert to title case. Console.WriteLine(tInfo.ToTitleCase(title)) End SubEnd Module
Categories: ASP.NET
Arts, convert string, Function (mathematics), Java, Letter case, Proper case, StrConv, String (computer science), upper case, Variants, vb.net
Comments (0)
Trackbacks (0)
Leave a comment
Trackback
Comments