TrimEnd() method in C#

CsharpProgrammingServer Side Programming

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
raja
Published on 16-Aug-2018 13:07:00
Advertisements