C# String TrimEnd
Description
String TrimEnd
removes all trailing occurrences of a
set of characters specified in an array from the current String object.
Syntax
String.TrimEnd
has the following syntax.
public string TrimEnd(
params char[] trimChars
)
Parameters
String.TrimEnd
has the following parameters.
trimChars
- An array of Unicode characters to remove, or null.
Returns
String.TrimEnd
method returns The 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
null or an empty array, Unicode white-space characters are removed instead.
Example
The following example demonstrates how you can use the TrimEnd(Char[]) method to trim white space or punctuation marks from the end of a string.
using System;/* ww w .jav a 2s . co m*/
public class TrimEnd
{
public static void Main()
{
string sentence = "The dog had a bone, a ball, and other toys.";
char[] charsToTrim = {',', '.', ' '};
Console.WriteLine(sentence.TrimEnd(charsToTrim));
}
}
The code above generates the following result.