vcent Posted March 11, 2009 Posted March 11, 2009 Hi. I have a text file like this [APPLE] Color: Red Quantity: 100 Country: France [Orange] Color: Orange Quantity: 300 Country: China I want to use a loop to check for Apple and get the country. The outer loop is easy. I can use a while....wend to get apple. But how do I get the 2nd item. Thanks.
Triblade Posted March 11, 2009 Posted March 11, 2009 This looks like how an ini-file is build. Maybe if the rest of the text file is the same you could port it to the ini format? Then this would make it a lot easier. My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
BrettF Posted March 11, 2009 Posted March 11, 2009 Convert it to a 2D array was my method... expandcollapse popup#include <Array.au3> Global $aOutPut[1][4] ;[n][0] = Fruit ;[n][1] = Colour ;[n][2] = Quantity ;[n][3] = Country Global $iCount = 0 Global $ic = 0 $textfile_contents = "[APPLE]" & @CRLF $textfile_contents &= "Color: Red" & @CRLF $textfile_contents &= "Quantity: 100" & @CRLF $textfile_contents &= "Country: France" & @CRLF & @CRLF $textfile_contents &= "[Orange]" & @CRLF $textfile_contents &= "Color: Orange" & @CRLF $textfile_contents &= "Quantity: 300" & @CRLF $textfile_contents &= "Country: China" $aText = StringSplit ($textfile_contents, @CRLF, 1) _ArrayDisplay ($aText) For $i = 1 To $aText[0] If StringRegExp ($aText[$i], "(\[)(.*?)(\])") Then $iCount += 1 $iC = 0 ReDim $aOutPut[$iCount + 1][4] $aOutPut[$iCount][$iC] = StringTrimRight(StringTrimLeft ($aText[$i], 1),1) $ic += 1 ElseIf $aText[$i] <> "" Then $aOutPut[$iCount][$iC] = StringTrimLeft ($aText[$i], StringInStr ($aText[$i], ": ", 1)) $ic += 1 EndIf Next $aOutPut[0][0] = $iCount _ArrayDisplay ($aOutPut) Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now