TrimStart() method removes all leading occurrences of a set of characters, whereas TrimEnd()removes all trailing occurrences of a set of characters.
The TrimStart() method removes all leading occurrences of a set of characters specified in an array.
Let us see an example to remove all leading zeros −
using System; class Program { static void Main() { String str ="0009678".TrimStart(new Char[] { '0' } ); Console.WriteLine(str); } }
9678
The TrimEnd() method removes all trailing occurrences of a set of characters specified in an array.
Let us see an example to remove all trailing 1s −
using System; class Program { static void Main() { String str ="7341111".TrimEnd(new Char[] { '1' } ); Console.WriteLine(str); } }
734