1. Re: [If/then and sequences...]

> Why, indeed, doesn't  "find" find more than the first occurrence of a pattern?
> If it did as you suggested, returning a sequence of "hits", that one feature
> alone would have saved me a tremendous amount of work in the last program
> I wrote.
all ya had to do was ask ;)

----tested code

function find_all(object test, sequence data)
----returns all the indexes the find() function
----matches, instead of just the first index only
----accepts same parameters as find()
----if no match found, it returns 0, as find() does
object result
   result = {}
   for i = 1 to length(data) do
      if equal(test,data[i]) then
         result &= i
      end if
   end for
   if length(result) then
        return result
   else return 0
   end if
end function

--------------------------------------
constant blah = {10,20,3,1,3,4,11,15}
constant names = {"mary","john","mary","frank",""}
constant zippy = {{12,13,14,15},{11,12,13,14,15},{10,11,12,13,14}}

? find_all(3,blah)
---output is {3,5}
? find_all(11,blah)
---output is {7}
? find_all(28,blah)
---output is 0
? find_all("mary",names)
---output is {1,3}
? find_all("john",names)
---output is {2}
? find_all("joebob",names)
---output is 0

---these are tricky ;)
? find(12,zippy)
---output is 0
? find_all(12,zippy)
---output is 0, just like find()


that help anyone????
and match_all() might be a wee tougher to code, and
i dont have time at this point to hack it out...

--Hawke'


_______________________________________________
Why pay for something you could get for free?
NetZero provides FREE Internet Access and Email
http://www.netzero.net/download/index.html

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu