Solved

Treat Consecutive Delimiters as One

Posted on 2002-03-05
3
661 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
ID: 6841803
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
ID: 6842135
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
ID: 6849258
Took me awhile to have time to try your code,
works perfectly,
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

920 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

12 Experts available now in Live!

Get 1:1 Help Now