C# Remove Trailing Comma Spaces And Zeros

C# Remove Trailing Comma Spaces And Zeros

Remove Trailling spaces commas zeros. In C#.net, you can easily remove trailing spaces,commas,zeros or any character. Trick is very simple, just pass the character array of comma,spaces and 0 to Trim function of string.

protected void Page_Load(object sender, EventArgs e)
{
string inputString = " String with trailing spaces and comma., ";
// Let's remove trailing spaces and comma.

string outputString = inputString.Trim(" ,".ToCharArray());

Response.Write(outputString);

}

output

String with trailing spaces and comma.

VB.net Example remove trailing spaces and commas from string.

Protected Sub Page_Load(sender As Object, e As EventArgs)
Dim inputString As String = " String with trailing spaces and comma., "
' Let's remove trailing spaces and comma.

Dim outputString As String = inputString.Trim(" ,".ToCharArray())

Response.Write(outputString)

End Sub

C# Remove all spaces from string example.

protected void Page_Load(object sender, EventArgs e)
{
string inputString = " String with trailing spaces and comma., ";
// Let's remove all spaces from string.

string outputString = inputString.Replace(" ", "");

Response.Write(outputString);

}

VB.net Remove all spaces from string.

Protected Sub Page_Load(sender As Object, e As EventArgs)
Dim inputString As String = " String with trailing spaces and comma., "
' Let's remove all spaces from string.

Dim outputString As String = inputString.Replace(" ", "")

Response.Write(outputString)

End Sub

Summery We saw how to use Trim function in .net and how to pass character array to remove unwanted characters from string.

Tags:

Remove internet explorer[C#] Remove Last Character From StringConvert Array To Comma Separated String C#C# Read CSV FileC# foreach loopSplit String In C#Replace string in C#c# arraylistc# stringhow to remove Google ChromeJQuery add/remove Class Dynamically

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.