SiteMap  | About    

How to VB.NET String.substring()

Substring in Vb.Net String Class returns a new string that is a substring of this string. The substring begins at the specified given index and extended up to the given length.

Public Function Substring(ByVal startIndex As Integer, ByVal length As Integer) As String


startIndex: The index of the start of the substring.

length: The number of characters in the substring.


The specified substring.


System.ArgumentOutOfRangeException : the beginIndex or length less than zero, or the begin index + length not within the specified string

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

        Dim str As String
        Dim retString As String
        str = "This is substring test"
        retString = str.Substring(8, 9)

    End Sub
End Class

When you execute this program , its will display "subtring" in the messagebox. (C) 2018    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.