Page 1 of 1 1
Topic Options
#108558 - 2003-11-20 05:56 PM Reading variable content one line at a time
kmurphy Offline
Fresh Scripter

Registered: 2000-04-21
Posts: 15
Loc: Nashua, NH USA
I have started a script that reads the section names of an ini file into a variable. When I display the variable to the screen, the section names are listed vertically.

How can I read each section name individually? I know I could write this data to a file, open it, and then read each line. But, I'm hoping there's a more elegant way.

Here's some more detail from my testing:
Here's the sample ini file:
contents of test.ini:
[section 1]
data1=test1

[section 2]
data1=test2

[section 3]
data1=test3

[section 4]
data1=test4

Here is the test script so far:
Contents of test.kix:
$temp = readprofilestring("c:\test.ini","","data1")
? $temp

This displays the following to the screen:
section 1
section 2
section 3
section 4

Therefore, the real question is; How can I read each line in this variable? If I could display each line, then I could perform an action using each line as a variable unto itself.

Any assistance would be appreciated.

Thanx,
Kevin Murphy
_________________________

Thanx,
Kevin Murphy

Top
#108559 - 2003-11-20 06:21 PM Re: Reading variable content one line at a time
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Think you would be looking for something like this:

Code:

break on

for each $section in split(readprofilestring("c:\test.ini","",""),CHR(10))

if $section

$data1 = readprofilestring("c:\test.ini",$section,"data1")

if $data1

?"data1=" + $data1

endif

endif

next


Top
#108560 - 2003-11-20 07:15 PM Re: Reading variable content one line at a time
kmurphy Offline
Fresh Scripter

Registered: 2000-04-21
Posts: 15
Loc: Nashua, NH USA
This works great, thank you!!!
_________________________

Thanx,
Kevin Murphy

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.052 seconds in which 0.021 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org