Reading text files
Posted: Wed Jul 31, 2013 5:14 pm
Hi,
I have a text file like this:
question*answer1*answer2*answer3*answer4*answer5*3 (the 3 indicating which is the correct answer - but this is not relevant)
(the file contains hundreds of lines)
What is the best way to get it into arrays?
I want it like this:
question[1 to 100] (let's assume there's 100 questions)
answer1[1..100] etc.
or
myArray[1][1] = question
myArray[1][2] = answer1
myArray[1][3] = answer2 and so on (is that even how you express multidimensional arrays) or would it be myArray[1,1] ?
I was thinking of doing the following:
put 1 into mycounter
repeat
read from file "myfille.txt" until "*"
put it into question[mycounter]
read from file "myfile.txt" until "*"
put it into answer1[mycounter]
etc...
read from file "myfile.txt" until return (after I read all the answers)
mycounter = mycounter + 1
until eof "myfile.txt"
I don't mind reading the whole file into a text variable and then do the parsing on that (I just don't know how to do that either)
Thanks,
Carel
I have a text file like this:
question*answer1*answer2*answer3*answer4*answer5*3 (the 3 indicating which is the correct answer - but this is not relevant)
(the file contains hundreds of lines)
What is the best way to get it into arrays?
I want it like this:
question[1 to 100] (let's assume there's 100 questions)
answer1[1..100] etc.
or
myArray[1][1] = question
myArray[1][2] = answer1
myArray[1][3] = answer2 and so on (is that even how you express multidimensional arrays) or would it be myArray[1,1] ?
I was thinking of doing the following:
put 1 into mycounter
repeat
read from file "myfille.txt" until "*"
put it into question[mycounter]
read from file "myfile.txt" until "*"
put it into answer1[mycounter]
etc...
read from file "myfile.txt" until return (after I read all the answers)
mycounter = mycounter + 1
until eof "myfile.txt"
I don't mind reading the whole file into a text variable and then do the parsing on that (I just don't know how to do that either)
Thanks,
Carel