[Haskell-cafe] Function to find a substring
tphyahoo at gmail.com
Mon Jun 7 14:31:35 EDT 2010
If you want to use libs to make your life easier, maybe something
along these lines?
Prelude Data.List.Split Safe> fmap length . headMay . split (onSublist
"asdf") $ "blee blah asdf bloo"
If they are big strings, it's probably faster to use bytestrings, or
arrays of some kinds, rather than default List implementation of
2010/6/6 R J <rj248842 at hotmail.com>:
> What's an elegant definition of a Haskell function that takes two strings
> and returns "Nothing" in case the first string isn't a substring of the
> first, or "Just i", where i is the index number of the position within the
> first string where the second string begins?
> Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox.
> Learn more.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe