Manipulating Strings in Lisp

Here are some handy ways to manipulate strings and convert between strings and lists:
.
Concatenation:
(concatenate 'string "a" "long" " " "the" " way") ;; returns "along the way".

(concatenate 'string "(" "let's make a list" ")")   ;; returns "(let's make a list)";

Turning strings into lists:
(read-from-string "(from string to list)")       ;; returns (FROM STRING TO LIST)
 ;; It also returns a second value, 21, which is the number of characters used in the string., but
 ;; you can safely ignore the second value, since Lisp will also ignore it unless you take special
 ;; steps to capture it and use it.

Turning a list into a string:
(format nil "~A" '(from list to string))   ;; returns "(FROM LIST TO STRING)"

Stripping parentheses off the ends of a string:

(let ((s "(getting rid of parens)"))
  (subseq s 1 (1- (length s))) )

;; returns  "getting rid of parens"

Here the SUBSEQ function takes three arguments: a sequence (in our case a string),
a starting index, and a stopping index.  It returns the subsequence that starts at
the starting index and that ends right before the stopping index.
 
 

(C) S. Tanimoto 2000