Programming Tutorials

Substring in Vb.Net String Class

By: Issac in VB.net Tutorials on 2009-01-30  

In VB.Net, Substring is a method of the String class that is used to extract a substring from a given string. It has two overloads:

  1. Substring(startIndex As Integer) As String: This overload returns the substring that starts at the specified startIndex and continues to the end of the string.

Example usage:

Dim str As String = "Hello, world!"
Dim subStr As String = str.Substring(7) 'subStr is "world!"
  1. Substring(startIndex As Integer, length As Integer) As String: This overload returns the substring that starts at the specified startIndex and has a length of length.

Example usage:

Dim str As String = "Hello, world!"
Dim subStr As String = str.Substring(7, 5) 'subStr is "world"

Note that startIndex is 0-based, which means that the first character in the string has an index of 0. Also, if startIndex or length is out of range, an exception will be thrown.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in VB.net )

Latest Articles (in VB.net)