Trim left String in C#

In this article we will discuss how to trim a string from left in C#.
  • 5925

The TrimStart method trims a string from the begging by removing white spaces from the start of a string.

The following code snippet shows how to trim a string from the start.

string firstName = "Mahesh";
string lastName = "Chand";
string age = "33";
string authorInfo = " Author "+ firstName + " " + lastName + " is "
    + age.ToString() + " years old.  ";
Console.WriteLine("Original
string:{0}", authorInfo);
Console.WriteLine("Lengh
:{0}", authorInfo.Length);
// Trim Start
string trimmedRightString = authorInfo.TrimEnd();
Console.WriteLine("Trimmed
right string:{0}", trimmedRightString);
Console.WriteLine("Lengh
:{0}", trimmedRightString.Length);

 

Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.