TrimEnd() method in C#


The TrimEnd() method removes all trailing occurrences of a set of characters specified in an array.

For example, the following string has trailing 1s.

String str ="234561111".

We can easily remove the above trailing 1s from a string using the TrimEnd() method.

Let us see an example to remove all trailing 1s.

Example

 Live Demo

using System;
class Program {
   static void Main() {

      String str ="234561111".TrimEnd(new Char[] { '1' } );
      Console.WriteLine(str);
   }
}

Output

23456

Updated on: 22-Jun-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements