Sign in to follow this  
Followers 0
ICANSEEYOU7687

Indexing a word?

5 posts in this topic

Basically, I am using the AD UDF, and I returned an Array with a bunch of names. Basically I am trying to create another array with all of the names that begin with a certain four letter word. Because these accounts need to be changed.

Here is kind of what I have so far, sorry its a bit messy

Global $aNotExpire[1]
Global $size
global $i
global $q
Global $NewArray[1]
$aNotExpire = _AD_GetPasswordDontExpire()
$size = $aNotExpire[0]
$i = 1
$q = 1

while $i <= $size

    
    $i = $i + 1
WEnd

Basically the $i, is indexing the first array, and $q will be indexing the second array "NewArray" which has not been created yet and is emtpy. I am trying to have it to through the while loop, and for every array index, search the word for a string, and if that string is present, it adds it to the new array.

Sorry if that is confusing. I am a little confused and getting these words to be indexed, and any help would be greatly appreciated.

thanks!

Share this post


Link to post
Share on other sites



So you have an array with the names you want? And you just want to search for a string and if it matches, toss them in a different array? And your array doesn't have an index?

I'd use a For/Next loop with Ubound. Then find the matches (not sure what the best way would be) and then give yourself a new array.

#include <Array.au3>
Dim $search = "jack"
Dim $Array[4] = ["jAckster","Jackie","jackso","Timbo"]
Dim $NewArray[1] = ["0"]
_ArrayDisplay($Array)
_ArrayDisplay($NewArray)

For $i = 0 To Ubound($Array) - 1
    If StringLower((StringLeft($Array[$i], 4))) = $search Then
        $n = $NewArray[0] + 1
        $NewArray[0] = $n
        ReDim $NewArray[$n + 1]
        $NewArray[$n] = $Array[$i]
    EndIf
Next

_ArrayDisplay($NewArray)

Rough example. Should get the job done though.

Share this post


Link to post
Share on other sites

Perfect!

Had to tweak it a little bit, but it worked great!

I got another request too... I think it would be done in a very similar way, but im not the best at programming...

Basically... lets say I got an array of 50 things that starts with WXYZ, I want to change this to, ABC. Any suggestions?

Once again thanks so much, and I apologize for my lack of programming knowledge... :graduated:

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Something like this?

#include <Array.au3>
Dim $Array[4] = ["WXYZ1","ZZZWXYZ22","WXYZWXYZ999","WXYABC9999999999999"]
_ArrayDisplay($Array)
For $i = 0 To Ubound($Array) - 1
    $Array[$i] = StringRegExpReplace($Array[$i], "\AWXYZ", "ABC")
Next
_ArrayDisplay($Array)

Edit:

Or maybe this is cleaner...

#include <Array.au3>
$String_In = "WXYZ"
$String_Out = "ABC"
Dim $Array[4] = ["WXYZ1","ZZZWXYZ22","WXYZWXYZ999","WXYABC9999999999999"]
_ArrayDisplay($Array)
For $i = 0 To Ubound($Array) - 1
    $Array[$i] = StringRegExpReplace($Array[$i], "\A" & $String_In, $String_Out) ; \A = force match at start of line
Next
_ArrayDisplay($Array)
Edited by Spiff59

Share this post


Link to post
Share on other sites

Woo, perfect.

Thanks, I am not familiar with a lot of the functions inside of autoit, and I appreciate your help!

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