From: Andy Spooner
Subject: Need SUBSTRING function
Date: 
Message-ID: <2cqq3fINN2nj@medicine.wustl.edu>
I need a function that takes a string and returns a substring
specified by the starting and ending character positions, e.g.:

> (substring "abcdefg" 2 5)
"cdef"

Anybody got one out there?

Thanks,

Andy

From: rodrigo vanegas
Subject: Re: Need SUBSTRING function
Date: 
Message-ID: <RV.93Nov23121623@fiji.cs.brown.edu>
In article <············@medicine.wustl.edu>, ·······@informatics.WUSTL.EDU (Andy Spooner) writes:

> I need a function that takes a string and returns a substring
> specified by the starting and ending character positions, e.g.:

>> (substring "abcdefg" 2 5)
> "cdef"

  (subseq "abcdefg" 2 (1+ 5))
  --> "cdef"


rodrigo vanegas
··@cs.brown.edu
From: Espen J. Vestre
Subject: Re: Need SUBSTRING function
Date: 
Message-ID: <2d203pINNif9@coli-gate.coli.uni-sb.de>
In article <················@fiji.cs.brown.edu> rodrigo vanegas,
··@cs.brown.edu writes:
> In article <············@medicine.wustl.edu>,
·······@informatics.WUSTL.EDU 
> (Andy Spooner) writes:
> 
> > I need a function that takes a string and returns a substring
> > specified by the starting and ending character positions, e.g.:
> 
> >> (substring "abcdefg" 2 5)
> > "cdef"
> 
>   (subseq "abcdefg" 2 (1+ 5))
>   --> "cdef"
> 

Using subseq is appropriate if a new string should be generated.  

If you need to do destructive manipulation on substrings (i.e. the
changes should be reflected in the main string), then something like this
is appropriate:

(defun substring (string start &optional end)
  (if (not end) (setq end (length string)))
  (make-array (- end start) :displaced-to string :displaced-index-offset
start))

________________________________________________________________________
 Espen J. Vestre,                                  ·····@coli.uni-sb.de
 Universit�t des Saarlandes,
 Computerlinguistik, Geb�ude 17.2
 Postfach 1150,                                 tel. +49 (681) 302 4501
 D-66041 SAARBR�CKEN, Germany                   fax. +49 (681) 302 4351