How can I create a newline inside a String? Is it possible without using IO ()
?
formatRow :: Car -> String
formatRow (a, d:ds, c, x:xs) = a ++ " | " ++ x ++ concat xs ++ " | " ++ show c ++ " | " ++ d ++ concat ds ++ (show '\n')
How can I create a newline inside a String? Is it possible without using IO ()
?
formatRow :: Car -> String
formatRow (a, d:ds, c, x:xs) = a ++ " | " ++ x ++ concat xs ++ " | " ++ show c ++ " | " ++ d ++ concat ds ++ (show '\n')
To create a string containing a newline, just write
"\n"
.Note that calling
show
on it will escape the newline (or any other meta-characters), so don't dofoo ++ (show "\n")
orfoo ++ (show '\n')
- just usefoo ++ "\n"
.Also note that if you just evaluate a string expression in ghci without using
putStr
orputStrLn
, it will just callshow
on it, so for example the string"foo\n"
will display as"foo\n"
in ghci, but that does not change the fact that it's a string containing a newline and it will print that way, once you output it usingputStr
.