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
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
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