Jump to content

Find and delete certain strings in array


 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...