Data.String (original) (raw)

Contents

Description

The String type and associated operations.

Synopsis

Documentation

class IsString a where Source #

Class for string-like datastructures; used by the overloaded string extension (-XOverloadedStrings in GHC).

Functions on strings

lines :: String -> [String] Source #

[lines](Data-String.html#v:lines "Data.String") breaks a string up into a list of strings at newline characters. The resulting strings do not contain newlines.

Note that after splitting the string at newline characters, the last part of the string is considered a line even if it doesn't end with a newline. For example,

>>> lines ""** **[]

>>> lines "\n"** **[""]

>>> lines "one"** **["one"]

>>> lines "one\n"** **["one"]

>>> lines "one\n\n"** **["one",""]

>>> lines "one\ntwo"** **["one","two"]

>>> lines "one\ntwo\n"** **["one","two"]

Thus `[lines](Data-String.html#v:lines "Data.String")` s contains at least as many elements as newlines in s.

words :: String -> [String] Source #

[words](Data-String.html#v:words "Data.String") breaks a string up into a list of words, which were delimited by white space.

>>> words "Lorem ipsum\ndolor"** **["Lorem","ipsum","dolor"]

unlines :: [String] -> String Source #

[unlines](Data-String.html#v:unlines "Data.String") is an inverse operation to [lines](Data-String.html#v:lines "Data.String"). It joins lines, after appending a terminating newline to each.

>>> unlines ["Hello", "World", "!"]** **"Hello\nWorld\n!\n"