kor Posted July 5, 2014 Share Posted July 5, 2014 (edited) #include <Array.au3> Local $aValues[2][2] = [["JobTitle1","Health Assistant, Health Aide"],["JobTitle2","Health Advisor"]] Local $sSearch = "Health" _ArrayDisplay($aValues) For $i = 0 To UBound($aValues) - 1 ConsoleWrite($aValues[$i][0] & " > ") ConsoleWrite(_ArraySearch($aValues, $sSearch, $i, $i, 0, 1, 1, 1) & @CR) Next The following code should have arraysearch fail both tests. While "Health" is contained within both rows they are not exact matches. Is there another way to accomplish this? I need a search of "Health" inside "Health Assistant" to fail because it's not an exact match. Edited July 5, 2014 by kor Link to comment Share on other sites More sharing options...
guinness Posted July 5, 2014 Share Posted July 5, 2014 Set $iCompare to 2. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
kor Posted July 5, 2014 Author Share Posted July 5, 2014 Set $iCompare to 2. That doens't work. If you change $iCompare to 2, and then set $sSearch to Health Advisor then row 0 should fail while row 1 succeeds. However that is not the behavior. Link to comment Share on other sites More sharing options...
sahsanu Posted July 5, 2014 Share Posted July 5, 2014 (edited) You could use regexp to exact match in your array search: #include <Array.au3> Local $aValues[3][2] = [["JobTitle1","Health Assistant, Health Aide "],["JobTitle2","Health Advisor"],["JobTitle3","Health"]] ;added Jobtitle3 for testing purposes Local $sSearch = "Health" _ArrayDisplay($aValues) For $i = 0 To UBound($aValues) - 1 ConsoleWrite($aValues[$i][0] & " > ") ConsoleWrite(_ArraySearch($aValues, "^" & $sSearch & "$", $i, $i, 0, 3, 1, 1) & @CR) ;added ^ and $ regexp to match exact search, also added 3 to $iCompare option Next Edit: That doens't work. If you change $iCompare to 2, and then set $sSearch to Health Advisor then row 0 should fail while row 1 succeeds. However that is not the behavior. Sorry, I'm a little asleep and I supposed that Guinnes suggestion (set $iCompare to 2) wasn't working for you but.... it is working as expected. Keep in mind that first result won't fail because the index to start and end is set to 0 and that means that is searching the entire array, maybe that is confusing you Here a working example with $iCompare set to 2: #include <Array.au3> Local $aValues[3][2] = [["Title","Description"],["JobTitle1","Health Assistant, Health Aide"],["JobTitle2","Health Advisor"]] Local $sSearch = "Health Advisor" _ArrayDisplay($aValues) For $i = 1 To UBound($aValues) - 1 ConsoleWrite($aValues[$i][0] & " > ") ConsoleWrite(_ArraySearch($aValues, $sSearch, $i, $i, 0, 2, 1, 1) & @CR) Next Cheers, sahsanu Edited July 6, 2014 by sahsanu Link to comment Share on other sites More sharing options...
kor Posted July 6, 2014 Author Share Posted July 6, 2014 Sorry, but both of your examples don't work. Example 1 using regexp fails because row 0 passes when it should fail. Example 2 fails because if you change $sSearch to "Health Assistant" row 1 doesn't pass. Link to comment Share on other sites More sharing options...
JohnOne Posted July 6, 2014 Share Posted July 6, 2014 So forget arraysearch and write your own. It's a few loops. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
mikell Posted July 6, 2014 Share Posted July 6, 2014 StringCompare($aValues[$i][1], $sSearch) shouldn't work ? Link to comment Share on other sites More sharing options...
Malkey Posted July 6, 2014 Share Posted July 6, 2014 Try this one. #include <Array.au3> Local $aValues[3][2] = [["JobTitle1", "Health Assistant, Health Aide "],["JobTitle2", "Health Advisor"],["JobTitle3", "Health"]] Local $sSearch = "Health" $Index = _ArraySearch($aValues, $sSearch, 0, 0, 0, 2, 1, 1) MsgBox(0, "", ($Index <> -1) ? "Found :" & $aValues[$Index][1] & " @ $aValues[" & $Index & "][1]" : "Not found") _ArrayDisplay($aValues) Link to comment Share on other sites More sharing options...
sahsanu Posted July 6, 2014 Share Posted July 6, 2014 Sorry, but both of your examples don't work. Example 1 using regexp fails because row 0 passes when it should fail. Example 2 fails because if you change $sSearch to "Health Assistant" row 1 doesn't pass. Sorry but Example 1 works, as I said, if you use 0 index to start the search and 0 to end it, it searches the entire array, that is the reason why you are receiving the index where it found the text. And sorry again but Example 2 works as expected too, you said you need EXACT match so if you search for "Health Assistant" it should find nothing, but if you search for "Health Advisor" it should find it. Link to comment Share on other sites More sharing options...
kor Posted July 6, 2014 Author Share Posted July 6, 2014 (edited) Try this one. #include <Array.au3> Local $aValues[3][2] = [["JobTitle1", "Health Assistant, Health Aide "],["JobTitle2", "Health Advisor"],["JobTitle3", "Health"]] Local $sSearch = "Health" $Index = _ArraySearch($aValues, $sSearch, 0, 0, 0, 2, 1, 1) MsgBox(0, "", ($Index <> -1) ? "Found :" & $aValues[$Index][1] & " @ $aValues[" & $Index & "][1]" : "Not found") _ArrayDisplay($aValues) Fails if you make $sSearch "Health Assistant" it doesn't find it in value [0][1] @sahsanu Example 2 fails. As you can see JobTitle 1 can have multiple values where JobTitle2 only has 1 possible value. Example 2 succeeds as long as the job titles only have 1 possible result, not multiple. That is my problem that I am running into. it also seems like I would need to string split the possible job titles and evaluate them individually rather than being able to search the column. Edited July 6, 2014 by kor Link to comment Share on other sites More sharing options...
mikell Posted July 6, 2014 Share Posted July 6, 2014 value [0][1] = "Health Assistant, Health Aide" $sSearch = "Health Assistant" There is NO EXACT match _ArraySearch won't work for this, a regex way would be better Link to comment Share on other sites More sharing options...
kor Posted July 6, 2014 Author Share Posted July 6, 2014 value [0][1] = "Health Assistant, Health Aide" $sSearch = "Health Assistant" There is NO EXACT match _ArraySearch won't work for this, a regex way would be better I agree. sahsanu provided an example for regexp but he edited it and moved it to _ArraySearch before I could try it. Link to comment Share on other sites More sharing options...
Solution mikell Posted July 6, 2014 Solution Share Posted July 6, 2014 (edited) Not very elegant but should work #include <Array.au3> Local $aValues[2][2] = [["JobTitle1","Health Assistant, Health Aide"],["JobTitle2","Health Advisor"]] Local $sSearch = "Health Aide" ;_ArrayDisplay($aValues) For $i = 0 To UBound($aValues) - 1 ConsoleWrite($aValues[$i][0] & " > ") ConsoleWrite(StringRegExp($aValues[$i][1], '(^' & $sSearch & '(?!\h*\w+))|(,\h*' & $sSearch & '(?!\h*\w+))') & @CR) Next Edited July 6, 2014 by mikell Link to comment Share on other sites More sharing options...
kor Posted July 6, 2014 Author Share Posted July 6, 2014 (edited) Not very elegant but should work #include <Array.au3> Local $aValues[2][2] = [["JobTitle1","Health Assistant, Health Aide"],["JobTitle2","Health Advisor"]] Local $sSearch = "Health Aide" ;_ArrayDisplay($aValues) For $i = 0 To UBound($aValues) - 1 ConsoleWrite($aValues[$i][0] & " > ") ConsoleWrite(StringRegExp($aValues[$i][1], '(^' & $sSearch & '(?!\h*\w+))|(,\h*' & $sSearch & '(?!\h*\w+))') & @CR) Next this works! but can you help me understand what the stringregexp is doing? EDIT: Also, after testing it seems as though the search is case sensitive. Any way to make it not care about case? Edited July 6, 2014 by kor Link to comment Share on other sites More sharing options...
guinness Posted July 6, 2014 Share Posted July 6, 2014 What AutoIt version fo you have? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
kor Posted July 6, 2014 Author Share Posted July 6, 2014 What AutoIt version fo you have? Latest from the website. just downloaded newest version from the website last week . Link to comment Share on other sites More sharing options...
guinness Posted July 6, 2014 Share Posted July 6, 2014 Well my advice produced -1. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
mikell Posted July 6, 2014 Share Posted July 6, 2014 This one is better and case insensitive StringRegExp($aValues[$i][1], '(?i)(^|,)\h*' & $sSearch & '(?!\h*\w+)') Sorry for the delay , had to sleep a little The regex matches $sSearch if preceded by start of string or a comma (^|,) and 0 or more spaces h*, but not followed by 0 or more spaces and 1 or more word characters (?!h*w+) (?i) for case insensitivity Link to comment Share on other sites More sharing options...
czardas Posted July 6, 2014 Share Posted July 6, 2014 (edited) Doing what JohnOne suggests and using the == operator is the most straight forward approach. It will be exact: ie. case sensitive etc... Having said that, I would have thought _ArraySearch() will do an equally good job. Edited July 6, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
mikell Posted July 6, 2014 Share Posted July 6, 2014 czardas, the problem is in matching "Health Assistant" or "Health Aide" but not "Health" in "Health Assistant, Health Aide" 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