Dimitris Anogiatis ha scritto: > Hey guys, > > I was wondering if there's a way to filter an array without having to go > through the whole thing > But, the whole thing would be 4 or 5 lines of code... it is not so much... > I've been experimenting with the Find method of the String[] but it only > looks for specific values > > ie: > ------------------------------------------------------------------------------------------ > PUBLIC e AS NEW String[] > > PUBLIC SUB Form_Open() > e.Add("D1", 0) > e.Add("D9 D7", 1) > e.Add("D3", 2) > e.Add("D2", 3) > e.Add("D4 D2", 4) > END > > PUBLIC SUB Button3_Click() > > Dim d AS Integer > > d = e.Find("D2") > PRINT d > > END > ------------------------------------------------------------------------------------------ > d will get the value 3. However the next value e.Find("D2) will result > to is a -1 (means the item's not found) > I don't understand: the first find() gives 3 (ok); the next "gives -1" or "should give -1"? > my questions are these > > 1) is it possible to put wildcards in the string Find is looking for? > so for example as to also catch "D4 D2"? > I am not sure, but I think "no". > 2) is there a workaround so I can only keep the values Find gives > out a result and discard the rest of the array so essentially I get > only those items I want and nothing else? > It seems cloudy to me, but something like:
i =0 while i<e.count if instr(e[i], "whatever")<>0 then break inc i wend if i=e.count then not_found else found in e[i] Note that: instead of a while you can use a for-next (less lines of code); instead of a break you can do something and then RETURN; instead of instr() you can use other functions (something like match()). Cheers, -- Doriano Blengino "Listen twice before you speak. This is why we have two ears, but only one mouth." ------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://www.creativitycat.com _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user