Solved

Treat Consecutive Delimiters as One

Posted on 2002-03-05
3
660 Views
Last Modified: 2012-05-04
I'm using the following code to import a space
delimited file. Works fine if there is only
one space. How can I import files with a varied
number of spaces?
Line Input #s1, strField
   ary1 = Split(strField, " ")
outFields = UBound(ary1)
str1 = ary1(0)
str2 = ary1(1)
str3 = ary1(2)
0
Comment
Question by:nschulz777
3 Comments
 
LVL 13

Accepted Solution

by:
crazyman earned 50 total points
Comment Utility
Option Explicit
Function CompactSpaces(strText As String) As String
    Dim strTemp As String
    strTemp = strText
    While InStr(strTemp, "  ") > 0
        strTemp = Replace(strTemp, "  ", " ")
    Wend
    CompactSpaces = strTemp
End Function


Line Input #s1, strField
  ary1 = Split(CompactSpaces(strField), " ")
outFields = UBound(ary1)
str1 = ary1(0)
str2 = ary1(1)
str3 = ary1(2)



0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Add a reference to Microsoft VBScript Regular Expressions

Line Input #s1, strField

Set m_RegExp = New VBScript_RegExp_55.RegExp
With m_RegExp
    .Pattern = " +"    'Look for more than one blank
    .Global = True
    strField = .Replace(strField, " ")
End With
Set m_RegExp = Nothing

ary1 = Split(strField, " ")
outFields = UBound(ary1)
str1 = ary1(0)
str2 = ary1(1)
str3 = ary1(2)

Anthony
0
 
LVL 2

Author Comment

by:nschulz777
Comment Utility
Took me awhile to have time to try your code,
works perfectly,
Thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

16 Experts available now in Live!

Get 1:1 Help Now