help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: left-trim and right-trim for strings


From: Benjamin Lewis
Subject: Re: left-trim and right-trim for strings
Date: Mon, 23 Sep 2002 22:24:37 -0700
User-agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.1 (sparc-sun-solaris2.8)

On Tue, 24 Sep 2002, address@hidden wrote:

> 
> "Stefan Monnier <address@hidden>"
> <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.  ")
> `----

Hey, cool.  You could do (replace-regexp-in-string "[ \t\n]+" " " "    This
is  another     string.   ")

to remove doubled spaces.

-- 
Benjamin Lewis

Don't take life so serious, son, it ain't nohow permanent.
                -- Walt Kelly


reply via email to

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