... and if you want to search strings not single characters: findmatch s t e = take m . drop n $ t where m' = length e (n, m) = f 0 s f i s | take m' s == e = (i, m') | null s = (0, 0) | otherwise = f (i+1) (tail s)
findmatch "asdfasdf" "asdfxvdf" "fas" == "fxv" (this one skips equality checks before *and* after the match. feel free post the necessary modifications. :) matthias On Wed, Sep 20, 2006 at 02:22:29AM -0700, Carajillu wrote: > To: haskell-cafe@haskell.org > From: Carajillu <[EMAIL PROTECTED]> > Date: Wed, 20 Sep 2006 02:22:29 -0700 (PDT) > Subject: Re: [Haskell-cafe] Java or C to Haskell > > > Yes, they must be equal the whole way, I like this recursive solution :) > > Ketil Malde-3 wrote: > > > > Carajillu <[EMAIL PROTECTED]> writes: > > > >> compare function just compares the two lists and return true if they are > >> equal, or false if they are not. > > > >> find_match "4*h&a" "4*5&a" 'h' ----> returns '5' (5 matches with the h) > >> find_match "4*n&s" "4dhnn" "k" ----> returns '' (no match at all - lists > >> are different anyway) > > > > Must they be equal the whole way, or just up to the occurrence of the > > searched-for character? > > > > find_match (x:xs) (y:ys) c | x==c = Just y > > | x/=y = Nothing > > | True = find_match xs ys c > > find_match [] [] _ = Nothing > > > > Or, to check the whole list: > > > > find_match (x:xs) (y:ys) c | x==c && xs == ys = Just y > > | x/=y = Nothing > > | True = find_match xs ys c > > find_match [] [] _ = Nothing > > > > -k
signature.asc
Description: Digital signature
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe