I'd like to know whether my string starts with another string. For example:
startsWith "(" "(test string)" == True
Is there such a function that comes with Haskell?
Since strings are lists of characters, we can import Data.List
and use the general function isPrefixOf
:
isPrefixOf :: Eq a => [a] -> [a] -> Bool
Example:
Prelude Data.List> isPrefixOf "abc" "abcxyz"
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With