Sign in to follow this  
Followers 0
Dgameman1

Find and delete certain strings in array

3 posts in this topic

#1 ·  Posted (edited)

From my understanding, _ArrayDelete only works with index numbers.

So this is the code I have so far

#include <array.au3>
Global $Username = "idkwhatimdoingm"
Global $BlackList[2] = [0, $Username]
Local $arr = StringSplit("dgameman1.idkwhatimdoingm.ilikk.bls are my favorite. nirs", '.')
_ArrayDisplay($BlackList)
_ArrayDisplay($arr)
For $i = 0 To UBound($BlackList) - 1
    _ArrayDelete($arr, $BlackList[$i])
Next

_ArrayDisplay($arr)


As it is right now, when I go ahead and `_ArrayDisplay($arr)`, "idkwhatimdoingm" does not get removed, only the first row, and that is because "idkwhatimdoingm" is not a valid row number.

So how can I go about making it so that all the specified text inside of an array, can be searched with the text inside of another array, and then delete if it's found?

I attempted to do this but I just get an error

For $b = 0 To UBound($BlackList) - 1
    $BlackList = _ArraySearch($BlackList, $BlackList[$b])
Next

 

 

Edited by Dgameman1

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

when deletin in array looping from end to beginning is a good idea, because deleted indices have no affect to elements they have be to checked. Also the Blacklist can have more then 1 Element, so you need a second loop:

#include <array.au3>
Global $Username = "idkwhatimdoingm"
Global $BlackList[3] = [2, $Username," nirs"]
Local $arr = StringSplit("dgameman1.idkwhatimdoingm.ilikk.bls are my favorite. nirs", '.')
_ArrayDisplay($BlackList)
_ArrayDisplay($arr)
For $j = 1 To UBound($BlackList) - 1
    For $i= UBound($arr) - 1 To 1 Step -1
        ConsoleWrite($BlackList[$j]&" = "&$arr[$i]&"?" &@TAB)
        If String($BlackList[$j]) = String($arr[$i]) Then
            ConsoleWrite("True"&@CRLF)
            _ArrayDelete($arr, $i)
            ExitLoop ;only when sure each Element in $arr is unique
        Else
            ConsoleWrite("False"&@CRLF)
        EndIf
    Next
Next
$arr[0]=UBound($arr)-1
_ArrayDisplay($arr)

read my comment in script and console output. 

Edited by AutoBert
1 person likes this

Share this post


Link to post
Share on other sites

Oh wow. That makes a lot of sense. 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