Re: Parsing a text file
From: Lee Peedin (lee_at_DONOTSPAMMEsafedatausa.com)
Date: 09/22/04
- Next message: Michael: "Urgent! Batch Mode not working"
- Previous message: Matrix: "Re: How can I convert following vb function to VBscript???"
- In reply to: Tom Lavedas: "RE: Parsing a text file"
- Next in thread: Tom Lavedas: "Re: Parsing a text file"
- Reply: Tom Lavedas: "Re: Parsing a text file"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 22 Sep 2004 14:58:12 -0400
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
>>
- Next message: Michael: "Urgent! Batch Mode not working"
- Previous message: Matrix: "Re: How can I convert following vb function to VBscript???"
- In reply to: Tom Lavedas: "RE: Parsing a text file"
- Next in thread: Tom Lavedas: "Re: Parsing a text file"
- Reply: Tom Lavedas: "Re: Parsing a text file"
- Messages sorted by: [ date ] [ thread ]