- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
What is the difference between Trim() and TrimStart() methods in C#?
Trim
A string method that removes all the leading and trailing whitespaces in a string.
For example, the string “jack sparrow“ would be returned as the following without leading and whitespaces using trim().
jack sparrow
The following is an example −
Example
using System; namespace Demo { class Program { static void Main(string[] args) { string str = " Amit "; Console.WriteLine(str); // trim Console.WriteLine("After removing leading and trailing whitespace..."); string res = str.Trim(); Console.WriteLine(res); Console.ReadKey(); } } }
Output
Amit After removing leading and trailing whitespace... Amit
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 −
using System; class Program { static void Main() { String str ="0009678".TrimStart(new Char[] { '0' } ); Console.WriteLine(str); } }
Output
9678
- Related Articles
- Difference between TrimStart() and TrimEnd() in C#
- What is the difference between String.Copy() and String.Clone() methods in C#?
- What is the difference between String.Copy() and String.CopyTo() methods in C#?
- What is the difference between Write() and WriteLine() methods in C#?
- What is the difference between Read() and ReadLine() methods in C#?
- What is the difference between Read(), ReadKey() and ReadLine() methods in C#?
- What is the difference between non-static methods and abstract methods in Java?
- What is the difference between functions and methods in JavaScript?
- What is the difference between scipy.cluster.vq.kmeans() and scipy.cluster.vq.kmeans2() methods?
- What is the difference between switchClass() and toggleClass() methods in jQuery?
- What is the difference between $.closest() and $.parents() methods in jQuery?
- What is the difference between jQuery.offsetParent( ) and jQuery.parent() methods in jQuery?
- What is the difference between jQuery.html( ) and jQuery.append( ) methods in jQuery?
- What is the difference between jQuery.bind() and jQuery.live() methods in jQuery?
- What is the difference between jQuery.hide() and jQuery.remove() methods in jQuery?

Advertisements