Function: string-clean-whitespace

string-clean-whitespace is an autoloaded and byte-compiled function defined in subr-x.el.gz.

Signature

(string-clean-whitespace STRING)

Documentation

Clean up whitespace in STRING.

All sequences of whitespaces in STRING are collapsed into a single space character, and leading/trailing whitespace is removed.

Other relevant functions are documented in the string group.

View in manual

Probably introduced at or before Emacs version 28.1.

Shortdoc

;; string
(string-clean-whitespace " foo   bar   ")
    => "foo bar"

Aliases

org-string-clean-whitespace rng-collapse-space (obsolete since 29.1)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/subr-x.el.gz
;;;###autoload
(defun string-clean-whitespace (string)
  "Clean up whitespace in STRING.
All sequences of whitespaces in STRING are collapsed into a
single space character, and leading/trailing whitespace is
removed."
  (declare (important-return-value t))
  (let ((blank "[[:blank:]\r\n]+"))
    (string-trim (replace-regexp-in-string blank " " string t t)
                 blank blank)))