我试图在使用时从行尾删除 \r BS.getLine
。我尝试过使用hSetNewlineMode
,它适用于getLine
但不适用于BS.getLine
:
import qualified Data.ByteString.Char8 as BS
import Data.ByteString (ByteString)
import System.IO (hSetNewlineMode, universalNewlineMode, stdin)
main = do
hSetNewlineMode stdin universalNewlineMode
-- s <- BS.pack `fmap` getLine -- \r removed
s <- BS.getLine -- \r not removed
putStrLn $ show s
-- to test: perl -e 'print "this\r\n"' | runhaskell program.hs
还有什么我应该做的吗?