Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Search string x for any substring found in block y.

 [1/3] from: louisaturk::coxinet::net at: 10-Dec-2001 16:22


Rebol friends, Why won't the following function work? Is there a better way to do this? Is there a native rebol function for this that I have missed? Louis x: "There is a dog in the barn." y: ["pig" "dog" "skunk"] findany: func [ "Searches string x for any substring found in block y." x [string!] "string" y [block!] "block of substrings" ] [ count: 1 loop length? y [ if find x y/count [true break] count: count + 1 ] ] if findany x y [print found]

 [2/3] from: al:bri:xtra at: 13-Dec-2001 7:55


Louis wrote:
> findany: func [
Try: find-any: func [
> if find x y/count [true break]
Try: if found? find x y/:count [return true]
> if findany x y [print found]
Try: if find-any x y [print "found"] And this is a better replacement for 'findany: find-any: func [x [string!] Strings[block!]][ foreach String Strings [ if found? find x String [return true] ] ] I hope that helps somewhat! Andrew Martin ICQ: 26227169 http://valley.150m.com/

 [3/3] from: rebol665:ifrance at: 12-Dec-2001 22:41


Hi, Andrew I think this is a job for parse. rebol[] findany: func [x [string!] y [block!] /local rule][ foreach word y [ ; build a block like [to "dog" to end] rule: append append copy [to] word [to end] ;print [mold rule] if parse x rule [return true] ]; foreach return false ] x: "There is a dog in the barn" y: ["pig" "dog" "skunk"] xx: "Parse is an wonderful yet not so simple function" yy: ["rebol" "complex" "program"] yyy: ["rebol" "function"] findany x y findany xx yy findany xx yyy Patrick