
Hi I've written a function that checks for a substring in a given string. This seems like a common thing to do and was wondering if there is a function that does this in one of the standard modules. stringContains :: String -> String -> Bool stringContains _ [] = True stringContains [] _ = False stringContains (h:t) (h1:t1) = if h == h1 then stringContains t t1 else stringContains t (h1:t1) -- sashan http://sashan.netfirms.com -------------------------------------------------- Brain: Here we are, Pinky--at the dawn of time! Pinky: Narf, Brain. Wake me at the noon of time.

On Thu, 8 May 2003, sashan wrote:
Hi
I've written a function that checks for a substring in a given string. This seems like a common thing to do and was wondering if there is a function that does this in one of the standard modules.
stringContains :: String -> String -> Bool stringContains _ [] = True stringContains [] _ = False stringContains (h:t) (h1:t1) = if h == h1 then stringContains t t1 else stringContains t (h1:t1)
Do you intend the following behavior? *Main> "x.y.z" `stringContains` "xyz" True -- Dean

Dean Herington wrote:
On Thu, 8 May 2003, sashan wrote:
Hi
I've written a function that checks for a substring in a given string. This seems like a common thing to do and was wondering if there is a function that does this in one of the standard modules.
stringContains :: String -> String -> Bool stringContains _ [] = True stringContains [] _ = False stringContains (h:t) (h1:t1) = if h == h1 then stringContains t t1 else stringContains t (h1:t1)
Do you intend the following behavior?
*Main> "x.y.z" `stringContains` "xyz" True
Nope

I think you want something like: (import List)
stringContains s = any (s `isPrefixOf`) . tails
then we get: Prelude List> stringContains "hello" "hell" False Prelude List> stringContains "hello" "hello" True Prelude List> stringContains "llo" "hello" True -- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume On Thu, 8 May 2003, sashan wrote:
Dean Herington wrote:
On Thu, 8 May 2003, sashan wrote:
Hi
I've written a function that checks for a substring in a given string. This seems like a common thing to do and was wondering if there is a function that does this in one of the standard modules.
stringContains :: String -> String -> Bool stringContains _ [] = True stringContains [] _ = False stringContains (h:t) (h1:t1) = if h == h1 then stringContains t t1 else stringContains t (h1:t1)
Do you intend the following behavior?
*Main> "x.y.z" `stringContains` "xyz" True
Nope
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Thu, 08 May 2003 22:47:25 +1200
sashan
I've written a function that checks for a substring in a given string. This seems like a common thing to do and was wondering if there is a function that does this in one of the standard modules.
Hal Dume III has given a simple solution to you; if you are looking for something more elaborate and efficient you should consult some text on pattern-matching implementation; there are already written functions for pattern matching in haskell, but not in the standard library, try looking at the haskell site, maybe you are interested in http://www.dcs.gla.ac.uk/~meurig/regexp/ Vincenzo

G'day. On Thu, May 08, 2003 at 10:47:25PM +1200, sashan wrote:
I've written a function that checks for a substring in a given string. This seems like a common thing to do and was wondering if there is a function that does this in one of the standard modules.
No, but there's some code here: http://haskell.org/hawiki/RunTimeCompilation Cheers, Andrew Bromage
participants (5)
-
Andrew J Bromage
-
Dean Herington
-
Hal Daume III
-
Nick Name
-
sashan