Wednesday, 25 June 2014

.Net Tips : Remove only trailing white spaces from string using Regex with C#.Net and VB.Net example

It is very easy to remove string's trailing white space.

We can achieve using Regex. The Regex is "[ \t]+$".

Here is example of this.

In this example we are taking on string which has trailing white space. We can remove this spaces using Regex.

C#. Net Example :
string strData = "This string contains trailing white spaces             ";
strData = Regex.Replace(strData, "[ \t]+$", "");
Response.Write(strData);

VB.Net Examples :
Dim strData As String = "This string contains trailing white spaces             "
strData = Regex.Replace(strData, "[ \t]+$", "")
Response.Write(strData)


Click here for other post regarding Remove only leading white spaces from string using Regex with C#.Net and VB.Net example

Click here for other post regarding Remove leading and trailing white spaces from string using Regex with C#.Net and VB.Net example.  


No comments:

Post a Comment