vb.net - Find multiple haystacks between the same needle -


i trying develop application obtains data webpage.

lets webpage has following content:

<needle1>haystack 1<needle2> <needle1>haystack 2<needle2> <needle1>haystack 3<needle2> <needle1>haystack 4<needle2> <needle1>haystack 5<needle2> 

and have following vb.net code:

dim webclient new system.net.webclient dim fullpage string = webclient.downloadstring("page url here") dim extractedinfo string = getbetween(fullpage, "<needle1>", "<needle2>") 

getbetween following function:

function getbetween(byval haystack string, byval needle string, byval needle_two string) string     dim istart integer = instr(haystack, needle)     if istart > 0         dim istop integer = instr(istart, haystack, needle_two)         if istop > 0             dim value string = haystack.substring(istart + len(needle) - 1, istop - istart - len(needle))             return value         end if     end if     return nothing end function 

by using code mentioned, extractedinfo equal "haystack 1" because gets haystack first occurrence finds.

my question is: how setup extractedinfo kind of array in order second, third, fourth, etc... occurrences.

something like:

extractedinfo(1) = haystack 1 extractedinfo(2) = haystack 2 

thanks in advance!

edit: think asking. call getbetween function 1 time each set of "needles".

dim webclient new system.net.webclient dim fullpage string = webclient.downloadstring("page url here") dim extractedinfo list (of string) = getbetween(fullpage, "<needle1>", "<needle2>")  function getbetween(byval haystack string, byval needle string, byval needle2 string) list(of string)         dim result new list(of string)         dim split1 string() = split(haystack, needle).toarray         each item in split1             dim split2 string() = split(item, needle2)             dim include boolean = true             each element in split2                 if include                     if string.isnullorwhitespace(element) = false result.add(element)                 end if                 include = not include             next element         next item          return result end function 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -