C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Here: We call Remove with one argument. This indicates where the string will be stopped.
Tip: All characters following that position are eliminated. This is how a SetLength function on the String type would work.
Length: The Length of the String will always be equal to the argument passed to Remove (if valid).
String LengthVB.NET program that uses Remove function
Module Module1
Sub Main()
Dim value As String = "bird frog dog"
' Find position of last space.
Dim index As Integer = value.LastIndexOf(" "c)
' Remove everything starting at that position.
value = value.Remove(index)
Console.WriteLine("REMOVE RESULT: {0}", value)
End Sub
End Module
Output
REMOVE RESULT: bird frog
Argument 1: This is an Integer that indicates the starting index of the range of characters we want to remove.
Argument 2: This is the count of chars (part of the range) we want to remove. It is not an end index.
VB.NET program that uses Remove, range
Module Module1
Sub Main()
Dim value As String = "abcde"
' Remove 2 chars starting at index 1.
Dim removed As String = value.Remove(1, 2)
Console.WriteLine("RESULT: {0}", removed)
End Sub
End Module
Output
RESULT: ade
Tip: Because of this implementation, it is somewhat faster to directly call the Substring function.