Question : Vb.net String split on double and single space

Hi I have a string containing the following info  " 1 10  2"

note there are 3 pieces of information that I would like to get out into an array using split
the problem is that there are single and double blank spaces when I split on a space I get 4 fields which is not correct there should be 3. I also cant rely on there being a double space between the second and last info sometimes it will be between first and second or both . I can eliminat the initial space using Trim(string) just fine what is lef it the double spaces

Any suggestions as to how I could get around this ?

Michal

Answer : Vb.net String split on double and single space

       Dim sLine As String
        Dim iAt As Integer
        Dim strList As List(Of String) = New List(Of String)

        sLine = " 1 10  2"
        sLine = Trim(sLine)
        While (sLine <> "")
            iAt = sLine.IndexOf(" ")
            If iAt < 0 Then
                strList.Add(sLine)
                sLine = ""
            Else
                strList.Add(sLine.Substring(0, iAt))
                sLine = Trim(sLine.Substring(iAt))
            End If
        End While

Above code is tested.  strList will have 3 items.

You can use following to see what is in strList
        For intCount = 0 To strList.Count - 1
            MessageBox.Show("Value = " + strList(intCount))
        Next

HTH
Ashok
Random Solutions  
 
programming4us programming4us