Reading Text file

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Display Modes
  12 December 2009
Reading Text file

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:


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!
  12 December 2009
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
IllusionCatalyst Instrument set for 3ds Max │ AliquaForma Personal portfolio in fieri
  12 December 2009
Many thanks

Thanks Enrico, thats got it...
  12 December 2009
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 08:47 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.