emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string-strip


From: Lars Hansen
Subject: Re: string-strip
Date: Tue, 20 Jun 2006 08:34:15 +0200
User-agent: Debian Thunderbird 1.0.2 (X11/20060423)

Richard Stallman wrote:

>    > 3. Return nil when resulting string is empty.
>
>That would be a bad idea.
>  
>
Ok. Then what about

(defun string-strip (str)
  "Return a copy of STR with leading and trailing white space removed."
  (save-match-data
    (string-match
"\\`[[:space:]\n]*\\(\\(?:.\\|\n\\)*?\\)[[:space:]\n]*\\'" str)
    (match-string 1 str)))

(string-strip " foo ")      => "foo"
(string-strip " \nfoo\n ")  => "foo"
(string-strip " foo\nbar ") => "foo\nbar"
(string-strip " ")          => ""
(string-strip " \n ")       => ""





reply via email to

[Prev in Thread] Current Thread [Next in Thread]