barryb Posted March 15, 2011 Share Posted March 15, 2011 (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 March 21, 2011 by barryb Link to comment Share on other sites More sharing options...
hannes08 Posted March 15, 2011 Share Posted March 15, 2011 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] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 15, 2011 Moderators Share Posted March 15, 2011 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) EndIfYou 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
barryb Posted March 15, 2011 Author Share Posted March 15, 2011 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 Link to comment Share on other sites More sharing options...
barryb Posted March 21, 2011 Author Share Posted March 21, 2011 Hi Guys, thanks for your input and help, after some hiccups I got it working and now have it out for testing Cheers, Barry Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 21, 2011 Moderators Share Posted March 21, 2011 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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