welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Thursday, March 29, 2012

Remove large white space or split string using Regular expression

In this article we split a large whitespace using regular expression

Normally if we use normal split function using white space, it separate by each white space character..But by using regular expression, its very easy to split string using whit space..
Here I illustrate an example by code…
We have string like this…
Dim str As String = "1234567            12345         678594"

We want to separate only the numbers, In that case normal split function won’t help us…For that we for or regex expression.

Dim str As String = "1234567            12345         678594"
        Dim str1 As String()
        Dim rgs As Regex = New Regex("  +")
        str1 = rgs.Split(str)

The result the sr1 contains only 3 array. By using this regex pattern (“    +”), it easy to avoid the extra white space.

I hope you enjoy this method to split a string in large white space……….


Post a Comment