Jump to content

_ArraySearch , need EXACT match


Go to solution Solved by mikell,

Recommended Posts

#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 by kor
Link to comment
Share on other sites

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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

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 :P

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 by sahsanu
Link to comment
Share on other sites

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

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

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

 

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 by kor
Link to comment
Share on other sites

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

  • Solution

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 by mikell
Link to comment
Share on other sites

 

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 by kor
Link to comment
Share on other sites

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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

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