Visual Basic String Remove Method

In visual basic, the string Remove method is useful to delete characters in the string starting from the specified position and continues to the end of the string.

 

In case, if we want to delete a particular length of substring, we need to specify the starting position and length of the characters to delete from the given string.

 

Following is the pictorial representation of using string Remove() method to delete characters from string based on the defined starting position in visual basic programming language.

 

Visual Basic (VB) String Remove Method Representation Diagram

 

If you observe the above diagram, we removed all the characters from the defined string “Welcome to Tutlane”, starting from the position 5 using Remove method.

Visual Basic String Remove Method Syntax

Following is the syntax of defining a string Remove method to remove the characters starting from the defined position in the given string.

 

Public Function Remove(ByVal startIndex As Integer) As String

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

If you observe the above syntaxes, the first syntax is useful to delete all the characters in the string, starting from the defined position (startIndex) and the second syntax is useful to delete particular length of a substring by defining the starting position and length of the characters.

Visual Basic String Remove Method Example

Following is the example of using string Remove() method to delete characters in the string based on the defined position in visual basic programming language.

 

ModuleModule1

    Sub Main()

        Dim msg As String = "Welcome to Tutlane"

        Console.WriteLine("Remove Result: {0}", msg.Remove(5))

        Console.WriteLine("Remove with Length: {0}", msg.Remove(3, 7))

        Console.WriteLine("Press Enter Key to Exit..")

        Console.ReadLine()

    End Sub

End Module

If you observe the above example, we used string Remove() method to remove the characters starting from the position 5 till the end of the defined string and another Remove() method to delete 7 characters starting from the position 3.

 

When we execute the above visual basic program, we will get the result like as shown below.

 

Visual Basic String Remove Method Example Result

 

If you observe the above result, the string Remove() method has deleted the characters based on the defined positions and returned a remaining string characters.

 

This is how we can use string Remove() method to delete required characters from the given string based on the defined position in visual basic programming language.