Visual Basic .NET Power Tools
Team Fly |
Page 20
Whoever wrote the Help entry for the Split method evidently was unaware of this approach. The code example employs the bizarre, cumbersome ToCharArray method instead.
Note that VB programmers are unfamiliar with using braces in their programming, but in VB.NET they can be used to fill an array with values, as this example illustrates. The rest of the code is straightforward:
Dim delim As Char() = {'',"} Dim tt As String = "Barry Morgan, 12 Dalton Ln., Akron, OH, 22022" Dim split As String() 'create string array split = tt.Split(delim) For i As Integer = 0 To split.Length - 1 Console.WriteLine(split(i)) Next
Here's an even more exotic alternative syntax. It combines the declaration of the string array with the declaration of the character array:
Dim split As String() = tt.Split(New [Char]() {","})
This is exotic to VB programmers partly because it uses brackets in addition to braces—neither punctuation is used in classic VB. It's also exotic in that a single logical line of code manages to declare two arrays, and to add a value to the second array.
Whatever. It's fine that there are several ways to create and fill a character array. Just fiddle around until you come upon a syntax that works.
A Useful Class View Utility
WinCV (Windows Class Viewer) comes with .NET. It offers you yet another view of the details of every class.
TIP If you're not sure where to begin in WinCV or other Framework references, or if you want a useful descriptive overview of the available .NET classes, click on the Contents tab at the bottom of the VB.NET Help window, then follow this path in the tree in the left pane: Visual Studio .NET\.NET Framework\Reference\Class Library. You'll see all the namespaces there, and all the classes within them.
To add WinCV to the IDE, choose Tools
Choose Project Directory in the Initial Directory field, and click OK to close the Open File dialog box. WinCV is now available from the VB.NET Tools menu.
Team Fly |