[Haskell-cafe] Text search

Bayley, Alistair Alistair_Bayley at ldn.invesco.com
Tue May 17 03:35:49 EDT 2005


> From: Bulat Ziganshin [mailto:bulatz at HotPOP.com] 
> 
> if you really need KMP, you can find it at 
> http://haskell.org/hawiki/RunTimeCompilation
> 
> > find (isSuffixOf "needle") (inits "haystack")
> 
> find (isPrefixOf "needle") (tails "haystack")
> 
> if you need an index - add it with zip:
> 
> find (isPrefixOf "needle".snd) (zip [0..] (tails "haystack"))

Or:

findIndex (isPrefixOf "bla") (tails "dfvbdbblaesre")

(I asked for something similar a few weeks ago:
  http://www.haskell.org//pipermail/haskell-cafe/2005-April/009690.html
)

-----------------------------------------
*****************************************************************
Confidentiality Note: The information contained in this   message, and any
attachments, may contain confidential   and/or privileged material. It is
intended solely for the   person(s) or entity to which it is addressed. Any
review,   retransmission, dissemination, or taking of any action in
reliance upon this information by persons or entities other   than the
intended recipient(s) is prohibited. If you received  this in error, please
contact the sender and delete the   material from any computer.
*****************************************************************



More information about the Haskell-Cafe mailing list