#120169 - 2004-05-26 03:22 PM
Variable name incrementing in iterations
|
Scripter2004
Fresh Scripter
Registered: 2004-03-01
Posts: 31
Loc: Minneapolis, MN (USA)
|
I'm parsing each line of a text file to see if it contains a 'name=xxx' parameter. If so, I strip out everything but that 'name' parameter value. I want to put the first 'name' parameter value that I find in a variable called $Book1, the second one $Book2, etc. Is there a way to increment a variable name with every iteration? I know you can increment a variable *value*, but what its *name*?
Thx Ron
|
|
Top
|
|
|
|
#120171 - 2004-05-26 03:42 PM
Re: Variable name incrementing in iterations
|
Scripter2004
Fresh Scripter
Registered: 2004-03-01
Posts: 31
Loc: Minneapolis, MN (USA)
|
Oh right! So set up a Books array, and then put the first name in Books[0], the second one in Books[1], etc., right?
|
|
Top
|
|
|
|
#120172 - 2004-05-26 04:01 PM
Re: Variable name incrementing in iterations
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Thats it exactly.
If you don't know how big the array will be, you can create it dynamically.
There are a lot of ways of doing it, but here's one.
Take a file "bookfile.txt" with the following contents: Code:
name=Withering Bites name=Hairy Otter and the Fragrant rice of Doom name=20 Leeks under the Pea
This code will load the values into an array, then display them: Code:
If Not Open(1,"bookfile.txt") $s=ReadLine(1) While Not @ERROR If InStr($s,"name=")=1 If IsDeclared($aBooks) $aBooks=Split(Join($aBooks,"|")+"|"+SubStr($s,6),"|") Else $aBooks=Split(SubStr($s,6),"|") EndIf EndIf $s=ReadLine(1) Loop $=Close(1) EndIf For $i = 0 to Ubound($aBooks) $i+1 " " $aBooks[$i] ? Next
|
|
Top
|
|
|
|
#120173 - 2004-05-26 04:26 PM
Re: Variable name incrementing in iterations
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
you can use Readfile() to read a textfile into an array then use filterarray() to filter out every line without 'name=' on it
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1247 anonymous users online.
|
|
|