Francogrex <······@grex.org> writes:
> 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
Like this?
CL-USER> (let ((str "abcdef"))
(setf str (subseq str 0 (- (length str) 2)))
(format t "Chopped up version: ~A~%" str))
Chopped up version: abcd
NIL
Rupert
On Aug 12, 2:45 pm, Rupert Swarbrick <··········@gmail.com> wrote:
> Francogrex <······@grex.org> writes:
> > 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
>
> Like this?
>
> CL-USER> (let ((str "abcdef"))
> (setf str (subseq str 0 (- (length str) 2)))
> (format t "Chopped up version: ~A~%" str))
> Chopped up version: abcd
Ruby:
"abcdef"[0..-3]
==>"abcd"