From: Kenny
Subject: Re: trim a string
Date: 
Message-ID: <48a1e2be$0$29501$607ed4bc@cv.net>
Francogrex wrote:
> This below seems trivial but before I lose my mind figuring this out
> (been stuck on it for 3 hours probably a sign of a low IQ). I want to
> trim the last two letters in a string str below
> 
> (setf str "ADGRFAG")
> 
> I tried to write the following procedure
> 
> (let ((temp (remove (nth (1- (length str)) (coerce str 'list)) str)))
>   (remove (nth (1- (length temp)) (coerce temp 'list)) temp))
> 
> OUTPUT -> "DRF"
> 
> But it's bad because it doesn't limit itself to the last two
> characters but removes everything inside that is similar to them? How
> can I trim just the two last chars? Thanks

You are a wildman! I would use subseq and not even change it to a list. 
If I had a list to begin with, butlast takes an optional count.

hth, kt

-- 

$$$$$: http://www.theoryyalgebra.com/
Cells: http://common-lisp.net/project/cells/
BSlog: http://smuglispweeny.blogspot.com/