[Top][All Lists]

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


From: Andreas Roehler
Subject: string-strip
Date: Fri, 16 Jun 2006 10:07:14 +0200
User-agent: Thunderbird (X11/20060516)


quite often I need a function to correct user-input,
i.e. wrongly inserted white spaces.

Used `comment-string-strip' to that purpose, which
works fine so far. However, there are two problems with

- it's rather difficult to use, as its requires
 handling of three arguments, where just one would
 sufficient in the cases I need it.

- it's in newcomment.el, used for a special purpose
 there and may be changed. So I hesitate to
 make programs depend on them.

What about to introduce a simplified version of `comment-string-strip' into subr.el - if it's not already somewhere?

(defun my-string-strip (str)
 "Strip STR of any leading (if BEFOREP) and/or trailing (if AFTERP) space."
 (string-match "\\`\\s-*\\(.*?\\)\\s-*\n?\\'" str)
 (match-string 1 str))

(string-strip "asdf ")"asdf"
(string-strip " asdf")"asdf"
(string-strip " asdf ")"asdf"

Andreas Roehler

reply via email to

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