VBScript Skip blank spaces

Posted on 2012-09-04
Last Modified: 2013-09-25

I have the following code in my vbscript which split the txt file. Right now it only split by a blank space how to skip if there are more than one blank spaces in between?

Do While Not f.AtEndOfStream
   line = f.Readline
  columns = split(line, " ")
  strColumn1 = columns(0)
  strColumn2 = columns(1)
  strColumn3 = columns(2)

Question by:mrong
    LVL 51

    Accepted Solution

    Try this:

    line = f.Readline
    Do While Instr(line, "  ") > 0
       line = Replace(line, "  ", " ")
    columns = split(line, " ")
    strColumn1 = columns(0)
    strColumn2 = columns(1)
    strColumn3 = columns(2)

    Open in new window


    Author Comment

    changed to the followings and works.

    Do While Instr(strLine, "  ") > 0
             strLine = Replace(strLine, "  ", " ")
          arrNames = Split(strLine, " ")
            strColumn1 = arrNames(0)
            strColumn2 = arrNames(1)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now