TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET TextInfo Examples

Use the TextInfo type from System.Globalization. Call ToLower, ToUpper and ToTitleCase.
TextInfo. Sometimes we want to convert a string to lowercase, uppercase, or mixed case (title case). It is possible to use the ToLower and ToUpper methods on the String type.StringsToLower
But with TextInfo, we have access to ToLower, ToUpper and another method called ToTitleCase. We can convert a string to title case—where each letter following a space is uppercased.
An example. To begin, we acquire an instance of the TextInfo class. We get it through CultureInfo.InvariantCulture—the invariant part just means it won't change based on the system set up.

ToLower: With ToLower, we have the same effect as the string ToLower method—uppercase chars are converted to lowercase ones.

ToUpper: With ToUpper, we convert all lowercase chars to uppercase. Nothing else happens to the string.

ToTitleCase: This function converts each lowercase letter that follows a space to an uppercase letter.

VB.NET program that uses TextInfo Imports System.Globalization Module Module1 Sub Main() ' Get instance of TextInfo. Dim info1 As TextInfo = CultureInfo.InvariantCulture.TextInfo ' Convert string to lowercase with TextInfo. Dim result1 As String = info1.ToLower("BIRD") Console.WriteLine("TOLOWER: " + result1) ' Convert to uppercase. Dim result2 As String = info1.ToUpper("bird") Console.WriteLine("TO UPPER: " + result2) ' Convert to title case. Dim result3 As String = info1.ToTitleCase("blue bird") Console.WriteLine("TO TITLE CASE: " + result3) End Sub End Module Output TOLOWER: bird TO UPPER: BIRD TO TITLE CASE: Blue Bird
Some notes. For simple calls to ToLower and ToUpper, it is better to just use the String methods. These are used more often, and are easier to understand for other developers.
A summary. The ToTitleCase method is effective in converting a string into Title Case. For many simple applications, it is a better choice than a complex method that tests each char.Char
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf