Ash*_*Ash 31 string haskell newline
如何在String中创建换行符?没有使用可能IO ()吗?
formatRow :: Car -> String
formatRow (a, d:ds, c, x:xs) = a ++ " | " ++ x ++ concat xs ++ " | " ++ show c ++ " | " ++ d ++ concat ds ++ (show '\n')
Run Code Online (Sandbox Code Playgroud)
sep*_*p2k 58
要创建包含换行符的字符串,只需写入"\n".
请注意,调用"\r\n"它将转义换行符(或任何其他元字符),所以不要这样做- show或者foo ++ (show "\n")只是使用foo ++ (show '\n').
另请注意,如果你只是在不使用foo ++ "\n"or来评估ghci中的字符串表达式putStr,它只会调用putStrLn它,所以例如字符串show将显示为"foo\n"ghci,但这并不会改变它是包含换行符的字符串这一事实一旦你输出它将以这种方式打印"foo\n".