PDA

View Full Version : Reading Text file


mtompson
12-13-2009, 01:55 PM
Hi All
I'm trying to read individual lines from a .txt file, my script is:

*********************************************
f = openfile "C:\\GeoTime.txt"

while not eof f do

(

inputData = filterstring (readLine f) ","

)

close f

print "Line = "+inputData[1]

*********************************************

My .txt file reads:

Holocene
0
0.01

But when I run my script it prints '0.01' , I expected 'Holocene' for inputData[1]..

I expect:

inputData[1] = Holocene
inputData[2] = 0
inputData[3] = 0.01

any ideas?

Many thanks

PS Sorry if I posted this twice, computer acting funny!

SyncViewS
12-13-2009, 02:10 PM
Hi Mark,
If you want to read file lines from a file and store each line as string in an array, you first need to define the Array, then you can reach each line and append it to the array.

FilterString is not needed unless you need to split each line in tokens defined by the chars sequence.

Following code returns the results you expected.

(
local inputData = #()
local f = openfile "C:\\GeoTime.txt"

while (not eof f) do
(
append inputData (readLine f)
)

close f

for i = 1 to inputData.count do
format "inputData[%]: %\n" i inputData[i]
)

- Enrico

mtompson
12-13-2009, 03:56 PM
Thanks Enrico, thats got it... :)

CGTalk Moderation
12-13-2009, 03:56 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.