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

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

Re: a function for string splitting


From: Greg Hill
Subject: Re: a function for string splitting
Date: Tue, 26 Nov 2002 12:03:36 -0800

At 5:16 PM +0300 11/26/02, Luis O. Silva wrote:
Dear Emacs community,

I'm writing a function for translating dates in the form of a
string into Spanish and Russian. For example, you have:

"Thu, 21 Nov 2002 16:05:50 -0600 (CST)"

Within my function I used a `let' expression of the form:

(let ((day (substring "Thu, 21 Nov 2002 16:05:50 -0600 (CST)" 0 3))
       (month (substring "Thu, 21 Nov 2002 16:05:50 -0600 (CST)" 8 11)))
       ...)

All works fine provided that there isn't any date with
one-digit day, i. e., "Fri, 8 Nov 2002 11:56:37 -0500 (CST)"

My question is what function I could use for correctly
splitting the string.

Luis,

Give something like this a try:

(let*
 ((split-date (split-string "Thu, 21 Nov 2002 16:05:50 -0600 (CST)" " "))
 ((day-of-week (elt split-date 0))
 ((day-of-month (elt split-date 1))
 ((month (elt split-date 2))
 ...)

Be sure to use let* instead of let, since let does not guarentee the order of evaluation, and you always want split-date to be evaluated first.

--Greg




reply via email to

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