klequis / zz-haskell-notebook

Notes from learning Haskell
1 stars 0 forks source link

trim (aka strip) #71

Open klequis opened 2 years ago

klequis commented 2 years ago

If using Data.Text you can use strip, stripStart and stripEnd to trim text. If not using Data.Text I looked for a solution and liked this on the best:

import Data.Char (isSpace)
import Data.List (dropWhileEnd)

trimLeft :: String -> String
trimLeft = dropWhile isSpace

trimRight :: String -> String
trimRight = dropWhileEnd isSpace

trim :: String -> String
trim = trimLeft . trimRight