Sign in to follow this  
Followers 0
flaxcrack

_ArraySearch() Wildcards

11 posts in this topic

Is there any way to make _ArraySearch() use wild cards? The first part of the element of the array will always be static, but I need to search the entire array so I can find and display back that paticular array element.

Example:

[0] Hello

[1] My name is : Flax

[2] Good bye

I want to know if I can search for: My name is :

and have the _ArraySearch() return: My name is : Flax

Thanks!


[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this:

Dim $TESTARRAY[4]
$TESTARRAY[1] = 'Hello'
$TESTARRAY[2] = 'My name is : Flax'
$TESTARRAY[3] = 'Good bye'

$FindString = _ReturnStringArraySearch($TESTARRAY, 'My name is')
MsgBox(0, 'Test', $FindString)

Func _ReturnStringArraySearch(ByRef $n_Array, $f_FindString)
    For $i = 1 To UBound($n_Array) - 1
        If StringInStr($n_Array[$i], $f_FindString) Then Return $n_Array[$i]
    Next
EndFunc

Edit:

Messed up the code tag :lmao:

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Try this:

Dim $TESTARRAY[4]
$TESTARRAY[1] = 'Hello'
$TESTARRAY[2] = 'My name is : Flax'
$TESTARRAY[3] = 'Good bye'

$FindString = _ReturnStringArraySearch($TESTARRAY, 'My name is')
MsgBox(0, 'Test', $FindString)

Func _ReturnStringArraySearch(ByRef $n_Array, $f_FindString)
    For $i = 1 To UBound($n_Array) - 1
        If StringInStr($n_Array[$i], $f_FindString) Then Return $n_Array[$i]
    Next
EndFunc

Edit:

Messed up the code tag :lmao:

It runs like a CHAMP!!

[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Share this post


Link to post
Share on other sites
:lmao:

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

@Smoken

You should submit your function:

Func _ReturnStringArraySearch(ByRef $n_Array, $f_FindString)
    For $i = 1 To UBound($n_Array) - 1
        If StringInStr($n_Array[$i], $f_FindString) Then Return $n_Array[$i]
    Next
EndFunc

...To be in the next release of AutoIT! That is so excellent!


[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Share this post


Link to post
Share on other sites

Ha... your praise is wonderful ;) , but truley un-founded :lmao: , that will take care of your 'specific' needs at the moment... but would require a bit more work/parameters to be a UDF that others could benefit from rather than just returning the entire line.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Ha... your praise is wonderful ;) , but truley un-founded :lmao: , that will take care of your 'specific' needs at the moment... but would require a bit more work/parameters to be a UDF that others could benefit from rather than just returning the entire line.

I'm going to ask a really stupid question and please don't laugh as I'm still learning, but is your custom function AutoIT code? I look at it and some what understand it but I really don't understand all of it. I'm glad it works, but I would like to know how it works. Can you explain please?


[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Share this post


Link to post
Share on other sites

I'm going to ask a really stupid question and please don't laugh as I'm still learning, but is your custom function AutoIT code? I look at it and some what understand it but I really don't understand all of it. I'm glad it works, but I would like to know how it works. Can you explain please?

Eeek, you mean actually explain something?? :lmao:

Func _ReturnStringArraySearch(ByRef $n_Array, $f_FindString)
    For $i = 1 To UBound($n_Array) - 1
        If StringInStr($n_Array[$i], $f_FindString) Then Return $n_Array[$i]
    Next
EndFunc

Ok, I used the ByRef to make sure you passed a variable (array) to the function in that spot... in this case it would array you made $TESTARRAY, If I were reading a file, I would first probably use _FileReadToArray() and pass that Array to the ByRef $nArray parameter...

Like this, I'll comment it so maybe you can follow it a bit...

#include <File.au3>; Required include for _FileReadToArray()
Local $File2Open = FileOpenDialog('Open A Text File', @ScriptDir, 'All Text Files (*.txt)'); Used to find and open files easily
Local $DeclareArray; We have to have our variable that will be put in an array declared by Global/Dim/or Local
Local $StringToFind = 'a=recipient'; String to find in the file
_FileReadToArray($File2Open, $DeclareArray); Read the entire file into a single demensional array
MsgBox(0, 'Returned Array', _ReturnStringArraySearch($DeclareArray, $StringToFind)); This is just to see the return of the "1" instance we are looking for

Func _ReturnStringArraySearch(ByRef $n_Array, $f_FindString)
    For $i = 1 To UBound($n_Array) - 1
        If StringInStr($n_Array[$i], $f_FindString) Then Return $n_Array[$i]
    Next
EndFunc

;[$n_Array] is the variable that will hold our array we are passing from another function
; [$f_FindString] is the string we are looking for
;[For] the beginning of a loop like Do or While
; [$i] is going to hold the loops passes value in numbers.. ie, first pass $i = 1, 2nd pass $i = 2 etc... until the end of the file lines
; [1] is the starting point we will start looking at the array number
; [Ubound($n_Array) - 1] << this holds the total number of elements that the array we created holds
; [If] is going to make sure that this action we want to do is only carried out on our commands (a true or false)
; [StringInStr()] is going to allow us to search $n_Array (the array) [$i] the Line number (or element number) for the string we are looking for $f_FindString
; [Then] If this StringInStr() returns a 'True' in this case less than or greater than result of '0' Then we are telling it to
; [Return] Go back to the Function Call that you made, and give the Value that was found for the True If/Then Statement
; [Next] If nothing was found that we wanted to exit the loop on and Return, then continue the loop to the next $i number
; [EndFunc] If you reach this point you have finished your function call, and it will return from where you started to call it from, in our case if we reach it, it means the string was never found.

Remember, up for quite a long time here, so I hope I got everything correct so you could understand it, if not, the forum loves to correct other people, so I'm sure they will if something was told incorrectly.

Good Luck...

P.S., You may want to take a look at this post if you are new to AutoIt, LxP has done a great job on it: http://www.autoitscript.com/forum/index.ph...pic=19434&st=45


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Eeek, you mean actually explain something?? ;)

Hooray! I understand! :lmao: You are my new best friend!


[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Share this post


Link to post
Share on other sites

SmOke_N! Check me out with my very first real function:

$a = 1
$b = 5

$out  = Sum($a, $b)
MsgBox(0, "test", $out)

Func Sum(ByRef $num1, ByRef $num2)
    Local $var
    $var = $num1 + $num2
    Return $var
EndFunc

[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Share this post


Link to post
Share on other sites

SmOke_N! Check me out with my very first real function:

$a = 1
$b = 5

$out  = Sum($a, $b)
MsgBox(0, "test", $out)

Func Sum(ByRef $num1, ByRef $num2)
    Local $var
    $var = $num1 + $num2
    Return $var
EndFunc
Good deal... you do understand!

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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