use*_*323 6 string haskell char
简单的问题.
给定一个字符串,我希望能够输入一个字母,然后让我的函数计算字母出现在字符串中的次数.
countLetters :: String -> Char -> Int
Run Code Online (Sandbox Code Playgroud)
如何才能做到这一点?
bhe*_*ilr 12
同
countLetters :: String -> Char -> Int
countLetters str c = length $ filter (== c) str
Run Code Online (Sandbox Code Playgroud)
这只获得str相等的字符c,然后计算其长度.