Haskell Language Stripping whitespace


{-# LANGUAGE OverloadedStrings #-}

import qualified Data.Text as T

myText :: T.Text
myText = "\n\r\t   leading and trailing whitespace   \t\r\n"

strip removes whitespace from the start and end of a Text value.

ghci> T.strip myText
"leading and trailing whitespace"

stripStart removes whitespace only from the start.

ghci> T.stripStart myText
"leading and trailing whitespace   \t\r\n"

stripEnd removes whitespace only from the end.

ghci> T.stripEnd myText
"\n\r\t   leading and trailing whitespace"

filter can be used to remove whitespace, or other characters, from the middle.

ghci> T.filter /=' ' "spaces in the middle of a text string"