Wednesday, 18 June 2014

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

It is very easy to remove string's leading 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 leading white space. We can remove this spaces using Regex.

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

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


Click here for other post regarding Remove only trailing 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