Click to See Complete Forum and Search --> : Reading In a Space delimited File


TSmooth
July 18th, 2005, 07:41 AM
I was wondering what the best way to read in a space delimited file would be? I would love to just do a ReadLine() followed by a String.Split(" ") but the problem is that there is a variable amount of spaces between the values, not just one. Is there a way to make String.Split() treat consecutive delimiters as one? If not, what is the best way to read in a line of values and split them up? I have code that does this by reading one character at a time, checking if it is a space or tab and then reading and discarding until another non-space, non-tab character is found. It's pretty tedious though and I was wondering if there was an easier method.

- Tom

DeepButi
July 18th, 2005, 09:02 AM
TSmooth,
you can replace two spaces at a time in a loop before using split

While s.IndexOf(" ") >= 0
s = s.Replace(" ", " ")
MsgBox(s) ' just to see the progress
End While

Hope it helps

SatyaV
July 18th, 2005, 09:21 AM
You could also do the usual Split() with space/tab and then discard the undesirable entries by looping through the resulting array.