BlackHoleSun Posted April 12, 2011 Share Posted April 12, 2011 Is there a function to search within a string with values from an array? I want to take the computer model of a computer (i.e. "Computer Model 1234") and go through a list of possibles (i.e. "1234|2345|3456") and see if there was a match, and if so, what was matched. I don't think I can use StringInStr or _ArraySearch. Link to comment Share on other sites More sharing options...
taietel Posted April 12, 2011 Share Posted April 12, 2011 You can use StringRegExp. Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
wakillon Posted April 12, 2011 Share Posted April 12, 2011 (edited) Try this: #include <Array.au3> Dim $_StringArray[10] = [ 9, 'string1', 'string2', 'string3', 'string4', 'string5', 'string6', 'string7', 'string8', 'string9' ] ConsoleWrite ( "ArrayItem Index : " & _IsArrayItemInString ( $_StringArray, "string4" ) & @Crlf ) Func _IsArrayItemInString ( $_Array, $_Item ) For $_A = 1 To UBound ( $_Array ) - 1 If $_Array[$_A] <> '' And $_Array[$_A] = $_Item Then Return $_A Next Return False EndFunc ;==> _IsArrayItemInString ( ) Adjust script like you want... Edited April 13, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
BlackHoleSun Posted April 12, 2011 Author Share Posted April 12, 2011 Try this: #include <Array.au3> Dim $_StringArray[10] = [ 9, 'string1', 'string2', 'string3', 'string4', 'string5', 'string6', 'string7', 'string8', 'string9' ] ConsoleWrite ( "ArrayItem Index : " & _IsArrayItemInString ( $_StringArray, "string4" ) & @Crlf ) Func _IsArrayItemInString ( $_Array, $_Item ) For $_A = 1 To UBound ( $_Array ) - 1 If $_Array[$_A] <> '' And $_Array[$_A] = $_Item Then Return $_A Next Return False EndFunc ;==> _IsArrayItemInString ( ) Adjust script like you want... That worked. I didn't get it at first because I was trying to use just the model number instead of the whole computer name, but it seems to be working now. Thanks! Link to comment Share on other sites More sharing options...
wakillon Posted April 12, 2011 Share Posted April 12, 2011 That worked. I didn't get it at first because I was trying to use just the model number instead of the whole computer name, but it seems to be working now. Thanks! You can also, do a partial search with stringinstr by changing this line. If $_Array[$_A] <> '' And StringInStr ( $_Item, $_Array[$_A] ) <> 0 Then Return $_A AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
BlackHoleSun Posted April 12, 2011 Author Share Posted April 12, 2011 You can also, do a partial search with stringinstr by changing this line. If $_Array[$_A] <> '' And StringInStr ( $_Item, $_Array[$_A] ) <> 0 Then Return $_A That works even better. Thank you 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