Jump to content
Sign in to follow this  

how to chk multiple times in a text file

Recommended Posts


Hi. I have a text file like this


Color: Red

Quantity: 100

Country: France


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.


Share this post

Link to post
Share on other sites

Convert it to a 2D array was my method... :P

#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
$aOutPut[0][0] = $iCount

_ArrayDisplay ($aOutPut)

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.