C# Remove Trailing Comma Spaces And 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.
Currently rated 5.0 by 1 people
- Currently 5/5 Stars.
- 1
- 2
- 3
- 4
- 5