.NET Array Dictionary List String Sub ArrayList Cast Class Console Dates DataTable DateTime Enum File For Format If IndexOf Lambda LINQ Nothing Parse Process Property Regex Replace Select Sort Split StringBuilder Substring
ToUpper converts all characters to uppercase characters. It causes a copy to be made of the VB.NET String, which is returned. We look at ToUpper and its behavior on non-lowercase characters.
Example. This simple console program shows the result of ToUpper on the input String "r2d2". Notice how the "r" and "d" are the only characters that were changed. The non-lowercase letters ("2" and "2") are not changed.
Also: Characters that are already uppercase are not changed by the ToUpper Function.Char
VB.NET program that calls ToUpper on String Module Module1 Sub Main() Dim value1 As String = "r2d2" Dim upper1 As String = value1.ToUpper() Console.WriteLine(upper1) End Sub End Module Output R2D2
Uppercased. How can you determine if a String is already uppercase? This is possible by using ToUpper and then comparing the results of that against the original String. If they are equal, the string was already uppercased.
However, this is not the most efficient way. A faster way uses a For-loop and then the Char.IsLower function. If a Char is lowercase, the String is not already uppercase. It would return False early at that point.
Summary. We explored some aspects of the ToUpper function. This function changes no characters except lowercase characters. Digits and uppercase letters (as well as punctuation and spaces) are left the same.
Finally: We noted how to test Strings with a For-loop to see if they are uppercase.