开发者

Remove white space from string

I would like to rem开发者_StackOverflow中文版ove the whitespace located after \n.

For instance, username 123\n ugas 423\n peter 23\n asd234 would become username 123\nugas 423\npeter 23\nasd234.


I am assuming you want to remove one or more whitespace characters at the beginning of each line, not just the first whitespace character. Also, I think you want to remove any kind of whitespace characters, like tabs, not just literal space characters.

import Data.Char

stripLeadingWhitespace :: String -> String
stripLeadingWhitespace = unlines . map (dropWhile isSpace) . lines


f [] = []
f ('\n':' ':a) = f ('\n' : a)
f (a:b) = a : f b
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜