C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Note: TrimEnd receives a variable number of arguments. We pass them directly with no special syntax.
Note: You can see that the elements in the String array have had certain characters at their ends removed.
VB.NET program that uses TrimEnd function
Module Module1
Sub Main()
' Input array.
Dim array(1) As String
array(0) = "What's there?"
array(1) = "He's there... "
' Use TrimEnd on each String.
For Each element As String In array
Dim trimmed As String = element.TrimEnd("?", ".", " ")
Console.WriteLine("[{0}]", trimmed)
Next
End Sub
End Module
Output
[What's there]
[He's there]
Here: We remove two Char values from the String: the period and the space. These are part of a Character array.
CharChar ArrayNote: In the String literal, there are three periods and a space. All four of those characters are removed from the beginning.
VB.NET program that uses TrimStart
Module Module1
Sub Main()
Dim text As String = "... The Dev Codes"
Dim array(1) As Char
array(0) = "."
array(1) = " "
text = text.TrimStart(array)
Console.WriteLine("[{0}]", text)
End Sub
End Module
Output
[The Dev Codes]
Tip: You can create the Char array outside of the loop, or make it a Shared field. Then pass a reference to the existing array to TrimEnd.