Basic String Manipulation

Working with the members of System.String is as you would expect. Simply create a String variable and make use of the provided functionality via the dot operator. Do be aware that a few of the members of System.String are shared members and are therefore called at the class (rather than the object) level. Assume you have created a new Console Application named FunWithStrings and updated Main() as follows:

Module Program Sub Main()

Console.WriteLine("***** Fun with Strings *****") Dim firstName As String = "June"

Console.WriteLine("Value of firstName: {0}", firstName) Console.WriteLine("firstName has {0} characters.", firstName.Length) Console.WriteLine("firstName in uppercase: {0}", firstName.ToUpper()) Console.WriteLine("firstName in lowercase: {0}", firstName.ToLower())

Dim myValue As Integer = 3456787

Console.WriteLine("Hex vaule of myValue is: {0:X}", myValue) Console.WriteLine("Currency value of myValue is: {0:C}", myValue) End Sub End Module

Notice how the ToUpper() and ToLower() methods (as well as the Length property) have not been implemented as shared members and are therefore called directly from a String object.

Was this article helpful?

0 0

Post a comment