query
On this page

trim

lib.trim

Docs pulled from | This Revision | 18 minutes ago


Nixpkgs manual

Remove leading and trailing whitespace from a string s.

Whitespace is defined as any of the following characters: " ", "\t" "\r" "\n"

Inputs

s
The string to trim

Type

trim :: String -> String

Examples

lib.strings.trim usage example

trim "   hello, world!   "
=> "hello, world!"
(lib.strings.trim)

Noogle detected

Aliases

Implementation

The following is the current implementation of this function.

s:
    let
      # If the string was empty or entirely whitespace,
      # then the regex may not match and `res` will be `null`.
      res = match regex s;
    in
    optionalString (res != null) (head res)