Jump to content

Iniread wildcard?


Recommended Posts

Im looking for a way to use the iniread to find a group of sections maybe with a wildcard, but have no idea if it can even be done.

If the ini looked like this:

[1|2|3|4|5]

test=a|b|c|d

[1|3|3|4|5]

test1=a|b|c|d

[1|3|3|4|5]

test2=a|b|c|d

[1|4|3|4|5]

test3=a|b|c|d

I would want to be able to pull all data "[1|2" and get test=a|b|c|d or "[1|3" test1=a|b|c|d and test2=a|b|c|d

I have writen a long process that can do this that write a temp ini but was hoping for ideas or a trick to make it simple.

Switch StringRight($section, 1)
        Case "|"
            $doi = IniReadSectionNames("data\stock.ini")
            For $x = 1 To $doi[0]
                $doi2 = StringInStr($doi[$x], $section, 1)
                If $doi2 > 0 Then
                    $found1 = IniReadSection("data\stock.ini", $doi[$x])
                    If @error <> 1 Then
                        For $i = 1 To $found1[0][0]
                            IniWrite("data\Work.ini", "Found", $found1[$i][0], $found1[$i][1])
                        Next
                    EndIf
                EndIf
            Next
            $found = IniReadSection("data\Work.ini", "Found")
            For $x = 1 To $found[0][0]
                IniDelete("data\Work.ini", "Found", $found[$x][0])
            Next
        Case Else
            $found = IniReadSection("data\stock.ini", $section)
    EndSwitch

Hope that is enough code to get the point across.

Thanks for any help.

Link to comment
Share on other sites

  • Moderators

Blaq,

Welcome to the AutoIt forum. :)

Here is my take on how you might do it: ;)

$sFile = "stock.ini"

$sSearch = "1|3"  ; Or "1|2" if you wish

; Get section names
$aSections = IniReadSectionNames($sFile)

; Clear the result variable
$sResult = ""

; Loop through the sections
For $i = 1 To $aSections[0]
    ; if we find the search variable in the section name
    If StringInStr($aSections[$i], $sSearch) Then
        ; We get the key/value pairing
        $aKey = IniReadSection($sFile, $aSections[$i])
        ; And add them to the result
        $sResult &= $aKey[1][0] & "=" & $aKey[1][1] & @CRLF
    EndIf
Next

; And here we see what we got!
MsgBox(0, "Result for " & $sSearch, $sResult)

Any questions? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I tried something like that but didnt get it to work because the sections are really words not numbers and it has Organic and Inorganic and as you can see "inORGANIC" some words are in the others but it just hit me to turn on casesense. Now it is working great.

Thanks for the help!!

Link to comment
Share on other sites

  • Moderators

Blaq,

My pleasure. :)

the sections are really words not numbers and it has Organic and Inorganic

Top Tip: Give as much info as you can in the initial post (especially details like that!) and you will get replies that better fit your requirements - perhaps fortunately, we cannot read your mind. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...