Jump to content

_arraysearch FindAll?


Recommended Posts

Hello all, its been a while, good to be back ;) . Trying to search a string from a substring in a csv file, and then display the whole string.

For example, if I type "aut", I want a messagebox back that displays "autoit" if the word "autoit" is in the csv file. The following works, but only

displays the first instant. How can I make it return all instances, and using something like arraydisplay, be able to choose an item from the list of

results?

Code I have that works only for the first instant:

$csv=0
$input= "test"
_FileReadToArray("File.csv",$csv)
$searched= $input
$searches= _arraysearch($csv,$searched,0,0,0,1,1,0)
$record1=StringSplit($csv[$searches],",",0)
Msgbox(0,"",$record1)

The above example returs "testing" which is in the first cell in the csv file. theres also "testers" in the third row, but obviously the Msgbox is only returning "testing". So how can I use _arraysearch to grab and display all instants, and be able to select a specific instant from the list?

Any help is greatly apreciated!!

Link to comment
Share on other sites

in the help file you will find a function called _ArrayFindAll

use the partial search parameter.

you could also use a regexp to get what you want by just using a fileread instead of _filereadtoarray

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

richietheprogrammer,

I would use a RegEx like this: :)

#include <Array.au3>

; Declare an array to hold the instances
Global $aListing[1][3] =[[0, 0, 0]]

; Simulate a CSV file
$sCSV = "Autoit,Autarky,automatic,not_matched,Autumnal"

; Define the test string to search for
$sTest = "aut"

; Start looking
$iOffset = 1
While 1
    ; Find next instance of the test string
    StringRegExp($sCSV, "(?i)" & $sTest, 1, $iOffset)
    If @error Then
        ExitLoop
    EndIf
    ; Note the point at which the next search should start
    $iOffset = @extended

    ; Now move back to the comma at the beginning of the word or the start of the string
    $iStart = $iOffset + 1
    While 1
        $iStart -= 1
        If $iStart = 0 Or StringMid($sCSV, $iStart, 1) = "," Then
            $iStart += 1
            ExitLoop
        EndIf
    WEnd
    ; And now forward to the comma at the end of the word or the end of the string
    $iEnd = $iOffset - 1
    While 1
        $iEnd += 1
        If $iEnd > StringLen($sCSV) Or StringMid($sCSV, $iEnd, 1) = "," Then
            $iEnd -= 1
            ExitLoop
        EndIf
    WEnd

    ; Add to list
    $aListing[0][0] += 1
    ReDim $aListing[$aListing[0][0] + 1][3]
    $aListing[$aListing[0][0]][0] = StringMid($sCSV, $iStart, $iEnd - $iStart + 1)
    $aListing[$aListing[0][0]][1] = $iStart
    $aListing[$aListing[0][0]][2] = $iEnd

WEnd

_ArrayDisplay($aListing)

Please ask if anything is unclear. ;)

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

  • Moderators

richietheprogrammer,

Just use FileRead - you want the whole file in one variable not in an array. ;)

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

Wow, I feel dumb, not sure why I thought that was an array variable. Thank you! It works now, except one thing, which Im guessing has to do with the regexp code.

Basically, if the found item is the last item in that cell, the script grabs all the data after it, including the commas.

Example:

If I search "black" and in the csv file, there is "black color" , "color black" , and "irrelevant" seperate by commas (for csv), then the results will be:

-1- black color

-2- color black, irrelevant, and whatever might be after irrelevant..

Any idea how I can fix that? I found a temporary fix by adding a space before the commas, however that is only temporary and will cause problems with other functions. Thoughts? Thanks again!

Link to comment
Share on other sites

  • Moderators

richietheprogrammer,

Try changing the <<<<<<<<<<<<<<<<<<<<< line: :)

#include <Array.au3>

; Declare an array to hold the instances
Global $aListing[1][3] =[[0, 0, 0]]

; Simulate a CSV file
$sCSV = "black colour,colour black,black cat,not_matched,blackbird,shoeblack"

; Define the test string to search for
$sTest = "black"

; Start looking
$iOffset = 1
While 1
    ; Find next instance of the test string
    StringRegExp($sCSV, "(?i)" & $sTest, 1, $iOffset)
    If @error Then
        ExitLoop
    EndIf
    ; Note the point at which the next search should start
    $iOffset = @extended

    ; Now move back to the comma at the beginning of the word or the start of the string
    $iStart = $iOffset ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    While 1
        $iStart -= 1
        If $iStart = 0 Or StringMid($sCSV, $iStart, 1) = "," Then
            $iStart += 1
            ExitLoop
        EndIf
    WEnd
    ; And now forward to the comma at the end of the word or the end of the string
    $iEnd = $iOffset - 1
    While 1
        $iEnd += 1
        If $iEnd > StringLen($sCSV) Or StringMid($sCSV, $iEnd, 1) = "," Then
            $iEnd -= 1
            ExitLoop
        EndIf
    WEnd

    ; Add to list
    $aListing[0][0] += 1
    ReDim $aListing[$aListing[0][0] + 1][3]
    $aListing[$aListing[0][0]][0] = StringMid($sCSV, $iStart, $iEnd - $iStart + 1)
    $aListing[$aListing[0][0]][1] = $iStart
    $aListing[$aListing[0][0]][2] = $iEnd

WEnd

_ArrayDisplay($aListing)

That works for me. ;)

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

  • Moderators

richietheprogrammer,

It is hardcoded into the _ArrayDisplay function. You will need to write your own function based on the original or a completely new one. ;)

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...