CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2003
    Posts
    101

    Reading In a Space delimited File

    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

  2. #2
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Re: Reading In a Space delimited File

    TSmooth,
    you can replace two spaces at a time in a loop before using split

    Code:
    While s.IndexOf("  ") >= 0
        s = s.Replace("  ", " ")
        MsgBox(s)  ' just to see the progress
    End While
    Hope it helps
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  3. #3
    Join Date
    Jan 2005
    Posts
    70

    Re: Reading In a Space delimited File

    You could also do the usual Split() with space/tab and then discard the undesirable entries by looping through the resulting array.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured