Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Substring/Haskell/substring-2.hs
Normal file
31
Task/Substring/Haskell/substring-2.hs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
import qualified Data.Text as T (Text, take, drop, init, breakOn)
|
||||
import qualified Data.Text.IO as O (putStrLn)
|
||||
|
||||
fromMforN :: Int -> Int -> T.Text -> T.Text
|
||||
fromMforN n m s = T.take m (T.drop n s)
|
||||
|
||||
fromNtoEnd :: Int -> T.Text -> T.Text
|
||||
fromNtoEnd = T.drop
|
||||
|
||||
allButLast :: T.Text -> T.Text
|
||||
allButLast = T.init
|
||||
|
||||
fromCharForN, fromStringForN :: Int -> T.Text -> T.Text -> T.Text
|
||||
fromCharForN m needle haystack = T.take m $ snd $ T.breakOn needle haystack
|
||||
|
||||
fromStringForN = fromCharForN
|
||||
|
||||
-- TEST ---------------------------------------------------
|
||||
main :: IO ()
|
||||
main =
|
||||
mapM_
|
||||
O.putStrLn
|
||||
([ fromMforN 9 10
|
||||
, fromNtoEnd 20
|
||||
, allButLast
|
||||
, fromCharForN 6 "话"
|
||||
, fromStringForN 6 "大势"
|
||||
] <*>
|
||||
["天地不仁仁者人也🐒话说天下大势分久必合🍑合久必分🔥"])
|
||||
Loading…
Add table
Add a link
Reference in a new issue