| Copyright | (c) The University of Glasgow 2007 |
|---|---|
| License | BSD-style (see the file libraries/base/LICENSE) |
| Maintainer | libraries@haskell.org |
| Stability | stable |
| Portability | portable |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Data.String
Contents
Description
The String type and associated operations.
Documentation
class IsString a where Source #
Class for string-like datastructures; used by the overloaded string extension (-XOverloadedStrings in GHC).
Methods
fromString :: String -> a Source #
Instances
Instances details
Functions on strings
lines :: String -> [String] Source #
Splits the argument into a list of lines stripped of their terminating
\n characters. The \n terminator is optional in a final non-empty
line of the argument string.
For example:
>>>lines "" -- empty input contains no lines[]>>>lines "\n" -- single empty line[""]>>>lines "one" -- single unterminated line["one"]>>>lines "one\n" -- single non-empty line["one"]>>>lines "one\n\n" -- second line is empty["one",""]>>>lines "one\ntwo" -- second line is unterminated["one","two"]>>>lines "one\ntwo\n" -- two non-empty lines["one","two"]
When the argument string is empty, or ends in a \n character, it can be
recovered by passing the result of lines to the unlines function.
Otherwise, unlines appends the missing terminating \n. This makes
unlines . lines idempotent:
(unlines . lines) . (unlines . lines) = (unlines . lines)