Trim right String in C#

In this article we will discuss about how to trim the string from right in C#.
  • 5968

The TrimEnd method trims a string from the end by removing white spaces from the end of a string.

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

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);
string trimmedString = authorInfo.Trim();
Console.WriteLine("Trimmed string:{0}", trimmedString);
Console.WriteLine("Lengh
:{0}", trimmedString.Length);
// Trim End
string trimmedLeftString = authorInfo.TrimStart();
Console.WriteLine("Trimmed left string:{0}", trimmedLeftString);
Console.WriteLine("Lengh:{0}", trimmedLeftString.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.