Removes all trailing occurrences of a set of characters specified in an array from the current String object.
Assembly: mscorlib (in mscorlib.dll)
Public Function TrimEnd ( _
ParamArray trimChars As Char() _
) As Stringpublic string TrimEnd(
params char[] trimChars
)public:
String^ TrimEnd(
... array<wchar_t>^ trimChars
)member TrimEnd :
trimChars:char[] -> string
Parameters
- trimChars
- Type:
array< System. . :: . Char> [] () []
An array of Unicode characters to remove, ornull Nothing nullptr a null reference (Nothing in Visual Basic) .
Return Value
Type: SystemThe string that remains after all occurrences of the characters in the trimChars parameter are removed from the end of the current string. If trimChars is
The TrimEnd method removes from the current string all trailing characters that are in the trimChars parameter. The trim operation stops when the first character that is not in trimChars is encountered at the end of the string. For example, if the current string is "123abc456xyz789" and trimChars contains the digits from "1" through "9", the TrimEnd method returns "123abc456xyz".
Note |
|---|
This method does not modify the value of the current instance. Instead, it returns a new string in which all trailing characters found in trimChars are removed from the current string. |
The .NET Framework 3.5 SP1 and earlier versions maintains an internal list of white-space characters that this method trims if trimChars is
The following example demonstrates how you can use the TrimEnd(
Module TrimEnd
Public Sub Main()
Dim sentence As String = "The dog had a bone, a ball, and other toys."
Dim charsToTrim() As Char = {","c, "."c, " "c}
Dim words() As String = sentence.Split()
For Each word As String In words
Console.WriteLine(word.TrimEnd(charsToTrim))
Next
End Sub
End Module
' The example displays the following output:
' The
' dog
' had
' a
' bone
' a
' ball
' and
' other
' toys
using System;
public class TrimEnd
{
public static void Main()
{
string sentence = "The dog had a bone, a ball, and other toys.";
char[] charsToTrim = {',', '.', ' '};
string[] words = sentence.Split();
foreach (string word in words)
Console.WriteLine(word.TrimEnd(charsToTrim));
}
}
// The example displays the following output:
// The
// dog
// had
// a
// bone
// a
// ball
// and
// other
// toys
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note