Sign in to follow this  
Followers 0
cookiemonster

remove line from array if it contains .vss

6 posts in this topic

I have an array, and I want to remove all lines that contain '.png' in it, each line in the array contains something like 'C:folderfolderdog.png', so I need to be left only with only lines that do not contain .png

Can someone point me in the direction of how to do this to the array?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Best thing to do is check how your array is populated and avoid putting the data in it.

Checkout stringregexp in a "for loop". It is in the help file.

For the array you can use _ArrayDelete

Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

For $i = 1 to $array[0] -1

if stringinstr($array[$i], "png") then

Arraydelete($array, $array[$i])

next

... written on screen not checked

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Best thing to do is check how your array is populated and avoid putting the data in it.

Checkout stringregexp in a "for loop". It is in the help file.

For the array you can use _ArrayDelete

Agreed, but I imagine StringInStr will be quicker, or even StringRight.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Assuming the elements count is in $array[0]

For $i = $array[0] to 1 step -1
  If StringRight($array[$i], 4) = ".png" Then Arraydelete($array, $i)
Next

Loop backwards  :)

Share this post


Link to post
Share on other sites

This one should be faster, with only one redim :

Local $aList[10] = ["file1.txt", "file2.pdf", "file3.png", "file4.jpg", "file5.doc", "file6.png", "file7.rtf", "file8.png", "file9.zip", "file10.xlsx"]

Local $iIndex = 0
For $i = 0 To UBound($aList) - 1
    If StringRight($aList[$i], 4) <> ".png" Then
        $aList[$iIndex] = $aList[$i]
        $iIndex += 1
    EndIf
Next

Redim $aList[$iIndex]

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