Change the Case of All Characters in a String
Problem
You want to capitalize or de-capitalize all letters in a string.
Solution
Use the ToUpper or ToLower method of the String class.
Discussion
ToUpper method returns a new string that is all uppercase. The ToLower method returns a new string that is all lowercase.
Dim MixedCase, UpperCase, LowerCase As String MixedCase = "hELLo" UpperCase = MixedCase.ToUpper() ' UpperCase is now "HELLO" LowerCase = MixedCase.ToLower() ' LowerCase is now "hello"
If you want to operate on only part of a string, split the string as described in recipe Retrieve a Portion of a String, call ToUpper or ToLower on the appropriate substring, and then join the strings back together.
Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.