[futurebasic] text parsing

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2002 : Group Archive : Group : All Groups

From: David Cottrell <David.Cottrell@...>
Date: Thu, 21 Feb 2002 16:43:07 +1000
Hi all

This is really not my bag but can one of you text parsing demons show me 
a better way to parse a text file. This is what I have at the moment but 
it is way to slow.

I know I should read the file into a handle and parse that, I'm just not 
sure how to do it in this case as I only want part of the data in the 
file (in this case the first 4 values on each line of a tab separated 
data file).

Many thanks for enlightening me.

David

'~'1
local
dim as str255 target
dim as int theChar, strLength
dim as boolean delimiter
local fn parseLine$(theLine as str255)
target =""
glinePosition += 1'increment line position
theChar = theLine[glinePosition]'get char
strLength = len(theLine)
delimiter = _false

while delimiter = _false
target = target + chr$(theChar)
glinePosition += 1'increment line position
theChar = theLine[glinePosition]'get char
if theChar = _tab then delimiter = _true
if glinePosition > strLength then delimiter = _true
wend
end fn = target
'~'1


'~'1
local
dim as str255 rawLine, dummy, response, condition
dim as int trialNo, rt
local fn AnalyseFile (fileName as str255,WDrefNo as int)

open "I",1,fileName,,WDrefNo'open file and
do'find 'Trial' as
input#1,dummy'marker for start

long if left$(dummy,13) = "SubjectName: "
glinePosition = 13
gSubjectName = fn parseLine$(dummy)
end if

'line input#1,rawLine'marker for start
'dummy = left$(rawLine,5)'of data proper
until dummy = "Trial"

do
glinePosition = 0
line input#1,rawLine

if rawLine[1] = _tab then exit do
trialNo      = val(fn parseLine$(rawLine))
condition    = fn parseLine$(rawLine)
response     = fn parseLine$(rawLine)
rt           = val(Fn parseLine$(rawLine))

fn scoreResponses (condition,response,rt)

until eof (1)

close#1

end fn