Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[solved] how to delete array element?
#1
Hi,


I'm using an array to hold a list of urls. I'd like to delete urls that match certain domains.

I can't find anything in help file or in forum.

Are arrays the best way to manipulate lists? Thanks
#2
Do you mean something like this?

Macro Macro33
Code:
Copy      Help
ARRAY(str) arr.create(7)
arr[0]="a"
arr[1]="b"
arr[2]="c"
arr[3]="d"
arr[4]="e"
arr[5]="f"
arr[6]="g"

int i

;; Remove arr[2] >> 'c'
arr.remove(2)

;; Output array
for i 0 arr.len
,out F"arr[{i}]: {arr[i]}"
#3
Yes!

Thank you. How did you find that? I tried looking for 20 minutes and couldn't find anything.
#4
It's in the help, but you can miss it by accident:
- In help search for: OLE types: ARRAY , go to that chapter
- once in the chapter OLE types: ARRAY, [CTRL]+[F] and search for var.remove(index)
#5
When you search in the "Find help, functions, tools" and it does not find what you need, try to replace some words with synonyms.
For example, if you search for how to delete array element, it does not find the topic because there is no word "delete".
But if you replace "delete" to "remove", this help topic is the first in the list.
#6
Thank you both.
#7
I have a small problem. It says "invalid index". The offending code is at the bottom. The rest is there for context.

Code:
Copy      Help
;init array of strings, l
ARRAY(str) list_of_urls

int i

str pattern=
;<div class="morefg">\r\n.*<a href="(.*)">Read more

if(0=findrx(s pattern 1 4 list_of_urls)) end "not found"

;deletes urls that don't match domain
str d="domain.com"

for i 0 list_of_urls.len
    if find(list_of_urls[1 i] d) = -1
        list_of_urls.remove(1 i)

Thanks for reading.
#8
When removing array elements, use reverse for.

for i list_of_urls.len-1 -1 -1
#9
Thanks. I don't know if I would have ever solved that without you Confusedhock:


Forum Jump:


Users browsing this thread: 1 Guest(s)