Emacs Lisp Function to Trim String

Emacs Lisp Function to Trim String

Emacs lisp does not have a function that removes space from the beginning and end of a string. You must use “replace-regexp-in-string” for that. Here's a function that does it.

(defun trim-string (string)
  "Remove white spaces in beginning and ending of STRING.
White space here is any of: space, tab, emacs newline (line feed, ASCII 10)."
(replace-regexp-in-string "\\`[ \t\n]*" "" (replace-regexp-in-string "[ \t\n]*\\'" "" string))
)

See also:

Popular posts from this blog

Browser User Agent Strings 2012

11 Years of Writing About Emacs

does md5 creates more randomness?