The .NET string class has a method called substring. This is a powerful method when you want to break out a portion of a string. For example, if you have a string "Hello World" and only want the first word, you would take the substring of the first five characters. There are ways to call this method. The first accepts a starting position and the number of characters to retrieve, while the second accepts the starting location. The following code shows examples of using both of these methods on an instance of a string, and the resulting output is the first pair of strings shown in Figure 2-8:
' sub string
Dim substring = "Hello World"
TextBoxl.Text = substring.substring(0, 5) & Environment.NewLine
TextBoxl.Text &= substring.substring(6) & Environment.NewLine
TextBoxl.Text &= line & Environment.NewLine
Code snippet from Forml
Was this article helpful?