[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: left-trim and right-trim for strings
From: |
Klaus Berndl |
Subject: |
Re: left-trim and right-trim for strings |
Date: |
24 Sep 2002 15:09:18 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 |
On Tue, 24 Sep 2002, maierh@myself.com wrote:
>
> "Stefan Monnier <foo@acm.com>"
> <monnier+gnu.emacs.help/news/@flint.cs.yale.edu> writes:
>
> > How ironic. You used `split-string' just where `string-match' makes
> > more sense and then use `string-match' where `split-string' is just what
> > you need:
>
> > Why not
> >
> > (if (string-match "\\`[\n\t ]+" str) (substring str (match-end 0)) str)
> > ?
> > or
> > (if (string-match "\\`[\n\t ]*" str) (substring str (match-end 0))) ?
> >
>
> Since emacs-21 we have too `replace-regexp-in-string'. Personally, I
> like it very much.
>
> ,----
> | (replace-regexp-in-string "^ *" "" " This is a string. ")
> `----
Eureka! Yes, indeed, this is the one and only solution. It can be used for
left- right- and middle-trim without any if etc...Great.
But why are such trimming functions not included in the elisp-library? IMHO
they would be very useful for elisp-programmers?!
Klaus
P.S.
Nevertheless Stefans adjudgement about my first using of string-match and
split-string is correct ;-)
--
Klaus Berndl mailto: klaus.berndl@sdm.de
sd&m AG http://www.sdm.de
software design & management
Thomas-Dehler-Str. 27, 81737 München, Germany
Tel +49 89 63812-392, Fax -220