Posts: 197
Threads: 60
Joined: Dec 2013
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
Posts: 763
Threads: 261
Joined: Jul 2012
Do you mean something like this?
Macro
Macro33
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]}"
Posts: 197
Threads: 60
Joined: Dec 2013
Yes!
Thank you. How did you find that? I tried looking for 20 minutes and couldn't find anything.
Posts: 763
Threads: 261
Joined: Jul 2012
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)
Posts: 12,051
Threads: 140
Joined: Dec 2002
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.
Posts: 197
Threads: 60
Joined: Dec 2013
Posts: 197
Threads: 60
Joined: Dec 2013
I have a small problem. It says "invalid index". The offending code is at the bottom. The rest is there for context.
;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.
Posts: 12,051
Threads: 140
Joined: Dec 2002
When removing array elements, use reverse for.
for i list_of_urls.len-1 -1 -1
Posts: 197
Threads: 60
Joined: Dec 2013
Thanks. I don't know if I would have ever solved that without you
hock: