Reading Text file

Become a member of the CGSociety

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

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 12 December 2009   #1
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:

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!
 
Old 12 December 2009   #2
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
 
Old 12 December 2009   #3
Many thanks

Thanks Enrico, thats got it...
 
Old 12 December 2009   #4
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.
 
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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 12:51 AM.


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