Path: utzoo!attcan!uunet!husc6!uwvax!rutgers!apple!well!jax From: jax@well.UUCP (Jack J. Woehr) Newsgroups: comp.lang.forth Subject: Re: I need a word! Summary: You need *some* *words* ( Factor, factor, factor!) Keywords: Strings, COMPARE, search, match, PeeWee's Big Top Message-ID: <6760@well.UUCP> Date: 7 Aug 88 21:33:48 GMT References: <99@iisat.UUCP> Reply-To: jax@well.UUCP (Jack J. Woehr) Organization: Whole Earth 'Lectronic Link, Sausalito, CA Lines: 39 In article <99@iisat.UUCP> mackay@iisat.UUCP (Daniel MacKay) writes: > > >Now here's my problem: I've been out of forth for a couple of years, >and I need a word that can take a buffer address and a string address, >I guess, and return the address of the letter following first occurrance of >the string in the buffer! Try this: constant buffersize create foobuffer buffersize allot : find-first-string-match ( addr-of-string count-of-string ---- addr|false) buffersize over - 0 swap 0 \ install dummy fail flag do drop \ dummy fail flag 2dup foobuff i + swap compare \ 0 means perfect match 0= if foobuff i + leave then \ exit with addr, not fail 0 \ restore fail flag loop -rot 2drop ; \ lose srcaddr & ct : find-first-char-after-match ( $addr ct --- addr|false) dup >r \ save count find-first-string-match \ find where the string matches, if it does r> over \ bring back count if + else drop then ; \ if non-zero, addr was found, add count This is not entirely optimal, but if you examine these, and the source in your Forth system for the words called, you will probably be able to code something *real* fast. Good luck! Send us a copy ... :-) ************ jax@well jax@chariot " The only thing better than Forth is beer" JAX on GEnie