Sign in to follow this  
Followers 0
barryb

Search Array Query (Solved)

6 posts in this topic

#1 ·  Posted (edited)

Hi All,

I have a simple script that reads in a text file then searches for 3 strings and replaces them if found. All works OK but I have found out another tool that is being used is inserting a space in the strings I'm searching for :)

I was just going to duplicate what I already have and add the space string but wondered if there was a more eloquent and easily implemented method someone could suggest?

$sWinXP = "<OS VALUE=""WinXP""/>" <--- proper string
$sWinXPb = "<OS VALUE=""WinXP"" />"       <---- string now with added PITA space  
<snip>
        _FileReadToArray($sOSDpath, $aArray)
        _FileWriteLog($file, $sOSDpath & ' Preparing to migrate ')
        $iIndex = _ArraySearch($aArray, $sWinXP, 0, 0, 0, 1)
        If @error Then
            _FileWriteLog($file, $sWinXP & ' was not found in the array, skipping to next OSD file')
        Else
            _FileWriteLog($file, $sWinXP & ' was found in the array at position '& $iIndex & '.')
            $i7Index = _ArraySearch($aArray, $sWin7s, 0, 0, 0, 1)
            If @error Then
                _FileWriteLog($file, $sWin7s & ' was not found in the array, lets add it')
            ; Insert the string with our new value below the searched for string
                $iNew7 = $iIndex+1
            EndIf
Edited by barryb

Share this post


Link to post
Share on other sites



Hi barryp,

I'm not an expert in Regular Expressions, but there are loads of howtos and forums out there that can help you.

So what you are looking for in AutoIt is StringRegExpReplace

:)


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

barryb,

As Hannes123 has pointed out, this problem is trivial for StringRegExp. You will need to run a loop to look through the file array rather than using _ArraySearch, but the end result is the same. :)

Take a look at this proof of concept script:

; Simulate _FileReadToArray($sOSDpath, $aArray)
Global $aArray[6] = [5, "tom", "<OS VALUE=""WinXP""/>", "dick", "<OS VALUE=""WinXP"" />", "harry"]

For $i = 1 To $aArray[0]
    If StringRegExp($aArray[$i], '<OS VALUE="WinXP"\s{0,1}\/>') Then
        $iIndex = $i
        ExitLoop
    EndIf
Next
If $i = $aArray[0] + 1 Then
    ConsoleWrite("WinXP not found in the array, skipping to next OSD file")
Else
    ConsoleWrite("WinXP found on line " & $iIndex & @CRLF)
EndIf

You should get the "found on line 2" message at first - just alter the first WinXP string and it will find the one with a space in - alter both and it will find neither.

I imagine you have other strings to search for - if you let us have the optional versions for them all we can develop SREs for those too. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Thanks guys! I'm in and out of Autoit so am just a dabbler :)

What I will do is take your excelent example and advice then see if I can then fit it in to my script, if I'm not back in a week send out the search party :)

Cheers,

Barry

Share this post


Link to post
Share on other sites

Hi Guys,

thanks for your input and help, after some hiccups I got it working and now have it out for testing :)

Cheers,

Barry

Share this post


Link to post
Share on other sites

barryb,

Your week was nearly up - the search party was being formed! :)

Glad you got it working. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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  
Followers 0