• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 682
  • Last Modified:

Treat Consecutive Delimiters as One

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
nschulz777
Asked:
nschulz777
1 Solution
 
crazymanCommented:
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
 
Anthony PerkinsCommented:
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
 
nschulz777Author Commented:
Took me awhile to have time to try your code,
works perfectly,
Thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now