Remove blank space from row

I would like to remove the space after \n .

For example, username 123\n ugas 423\n peter 23\n asd234 becomes username 123\nugas 423\npeter 23\nasd234 .

+6
string haskell whitespace
source share
2 answers
 f [] = [] f ('\n':' ':a) = f ('\n' : a) f (a:b) = a : fb 
+5
source share

I assume that you want to remove one or more whitespace characters at the beginning of each line, not just the first space character. Also, I think you want to remove any whitespace characters, such as tabs, not just alphabetic spaces.

 import Data.Char stripLeadingWhitespace :: String -> String stripLeadingWhitespace = unlines . map (dropWhile isSpace) . lines 
+15
source share

All Articles