Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
How can i remove white space from right side of string in c# win. form?
Example:-
Hello__World_____//Here "_" means a blank

OUTPUT
Hello__World

Note:- Between Hello and World white space should remain 2 and my text is bigger than a Theseus so don't suggest iteration or looping.

Till now i could just write
string s = "Hello  World     ";
s = s.Trim();

But this removes gap between hello and world


Thanks in advance
Posted
Updated 30-Oct-14 3:43am
v2

Try
C#
string s = "Hello  World     ";
s = s.TrimEnd();

Agent_Spock wrote:
.Trim() removes gap between hello and world

No. It won't.
Removes all leading and trailing white-space characters from the current String object
 
Share this answer
 
v3
Try s.TrimStart() to remove spaces at beginning and s.TrimEnd()to remove spaces at the end and simply s.Trim() to remove spaces on both sides;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900