![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between TrimStart() and TrimEnd() in C#
TrimStart() method removes all leading occurrences of a set of characters, whereas TrimEnd()removes all trailing occurrences of a set of characters.
TrimStart()
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 −
Example
using System; class Program { static void Main() { String str ="0009678".TrimStart(new Char[] { '0' } ); Console.WriteLine(str); } }
Output
9678
TrimEnd()
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 −
Example
using System; class Program { static void Main() { String str ="7341111".TrimEnd(new Char[] { '1' } ); Console.WriteLine(str); } }
Output
734
Advertisements