Anonymous user
Strip whitespace from a string/Top and tail: Difference between revisions
Strip whitespace from a string/Top and tail (view source)
Revision as of 15:54, 21 February 2022
, 2 years agoEmacs Lisp: Simplify solution
(Added solution for Action!) |
(Emacs Lisp: Simplify solution) |
||
Line 771:
=={{header|Emacs Lisp}}==
(defun trim-l (str)▼
(replace-regexp-in-string "^ +" "" str) )▼
As of Emacs 24.4, the subr-x.el library contains string trimming functions:
<lang Lisp>(string-trim-left " left center right ") ;=> "left center right "
(string-trim-right " left center right ") ;=> " left center right"
(string-trim " left center right ") ;=> "left center right"</lang>
(defun trim-r (str)▼
(replace-regexp-in-string " +$" "" str) )▼
This can be emulated by using regex replacement:
(defun trim (str)▼
(trim-l (trim-r str) ))▼
▲<lang Lisp>(defun string-trim-left (str)
=={{header|Erlang}}==
|