Sign in to follow this  
Followers 0
BlackHoleSun

Search a string using an array?

6 posts in this topic

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.

Share this post


Link to post
Share on other sites



#3 ·  Posted (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 by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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

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