Re: Parsing a text file

From: Tom Lavedas (tlavedas_at_hotmail.remove.com)
Date: 09/23/04


Date: Thu, 23 Sep 2004 07:33:07 -0700

But you don't handle the file format that was described ( a Location: line
followed by a Names: line, nor do you account for the possibility of there
being more or less than three names on the Names: line.

Tom Lavedas
===========

"Lee Peedin" wrote:

> I know this is a VBScript newsgroup and I'll probably get flamed for
> posting this, but I just couldn't help myself :-)
>
> Lee
>
> A possible Rexx solution :-)
>
> do while lines(infile)
> aline = linein(infile)
> parse var aline part1':' part2
> if part1 = 'Names' then
> parse var part2 name1','name2','name3
> end
>
>
>
> On Wed, 22 Sep 2004 06:19:04 -0700, "Tom Lavedas"
> <tlavedas@hotmail.remove.com> wrote:
>
> >An alternative to McKirahan's approach ...
> >
> >Dim aData, aLocations(), aNames(), idx, n
> >With CreateObject("Scripting.FileSystemObject")
> > adata = Split( _
> > Replace(.OpenTextFile("test.txt").ReadAll, vbNewline &
> >vbNewline, _
> > vbNewline), vbNewline)
> >End With
> >
> >n = 0
> >For idx = 1 to Ubound(adata) - 1 Step 2
> > Redim Preserve aLocations(n), aNames(n)
> > aLocations(n) = Split(adata(idx - 1), ":")(1) ' array of strings
> > aNames(n) = Split(Split(adata(idx), ":")(1), ",") 'array of string arrays
> > n = n + 1
> >Next
> >
> >' Note that the aNames array can hve different length arrays in each element
> >n = Ubound(aLocations)
> >wsh.echo "Name(s) for location ", aLocations(n), "is/are ", Join(aNames(n),
> >" ")
> >
> >This approach makes use of functions that reduce the need for so many loops.
> >
> >The text file can have up to one blank line between data lines. All data
> >must be in pairs of Locations/Names lines.
> >
> >Tom Lavedas
> >===========
> >
> >"davidadner" wrote:
> >
> >> I'm trying to figure out how to parse a text file,
> >> looking for particular values.
> >>
> >> Here's an example of what's in the text file.
> >> Location: New York
> >> Names: John, Bob, Frank
> >>
> >>
> >> I want to read in the file and take the 3 names and
> >> perform operations against them. I know how to read in a
> >> file and once I have the values, I can do what I need,
> >> but I'm not sure how to get just the 3 names. I figure I
> >> need to do some sort of parsing with colons and commas as
> >> delimeters, but I'm not sure how.
> >>
> >> TTIA
> >>
>
>
>