Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

clean up data in order to use split function

Status
Not open for further replies.

gbob

Programmer
Apr 18, 2002
5
US
I have a text file where I'll always want to get the 5th item for processing. Each item in each line of data is separated by spaces, but it's a variable number of spaces. I can't use the split function, because it expects only ONE space between each expression. How could I clean this up, so that only one space separates each expression, and thus allow me to use the split function? Or maybe there's something else I could use instead of split?
 
gbob,

I don't know if this will work but it might be worth a try. Try using the replace function to replace all double spaces with a single space and then run the split function.

Say your line of data is stored in the variable myLine.

Dim noDoubleSpace : noDoubleSpace =

do while noDoubleSpace = false

if inStr(myLine, " ") = 0 then
noDoubleSpace = true
else
Replace(myLine, " ", " ")
end if

loop

dim lineArray : lineArray = Split(myLine, " ") Mighty :)
 
Using that replace function inside the loop did the trick. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top