kmurphy
(Fresh Scripter)
2003-11-20 05:56 PM
Reading variable content one line at a time

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


ShawnAdministrator
(KiX Supporter)
2003-11-20 06:21 PM
Re: Reading variable content one line at a time

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



kmurphy
(Fresh Scripter)
2003-11-20 07:15 PM
Re: Reading variable content one line at a time

This works great, thank you!!!