Retrieve a String - VB.NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

The following code is used to retrieve a string based on the position of the string.
The substring method is the easiest way to get a string based on it's location and it's length.
In this example we will retrieve the string that it's position is 6 and the length of the string is 6. (Note that you sould always start counting the position from 0)

Dim txt As String = "I use Visual Basic language"
 txt = txt.Substring(6, 6)
 MsgBox(txt)

Output: Visual
Notice that the word Visual index position starts on 6 and then the length of the word is 6.
Therefore we used txt.Substring(6, 6)
Where the first 6 is the starting position, and the second 6 is the length.


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.