[ cl-cookbook-Feature Requests-954984 ] String section addition

"SourceForge.net" <[email protected]> Sun, 16 May 2004 14:38:44 -0700
Newsgroups gmane.lisp.cookbook
Message-ID <[email protected]>
Feature Requests item #954984, was opened at 2004-05-16 16:38
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=447475&aid=954984&group_id=46815

Category: None
Group: None
Status: Open
Priority: 5
Submitted By: Chris Capel (pdf23ds)
Assigned to: Nobody/Anonymous (nobody)
Summary: String section addition

Initial Comment:
I'm just getting into lisp, and I was very surprised by
the lack of a function in the ANSI standard for
replacing subsections of vectors (strings) with other
vectors. In C#, you can do something like

mySqlQuery.Replace("'", "\'")

to make it safe for inserting into a DB, and quoting
like that is something you do in tons of places in web
programming. So I think you should include a function
for replacing things in vectors like this. I found this
function on http://www.lisp-p.org/lht/, by Gene Michael
Stover (it was called "string-replace-all-faster" there).

(defun string-replace-all (source old new)
  "Replace all occurrences in 'source' of 'old' with
'new'."
  (do ((newlen (length new))
       (i (search old source)
          (search old source :start2 (+ i newlen))))
      ((null i) source)
      (setq source
            (concatenate 'string
	      (subseq source 0 i)
	      new
	      (subseq source (+ i newlen))))))

I haven't gotten his permission for anything, I just
found it. I modified the doc string a bit, and I
changed the order and name of the arguments, and the
name of the function.

Maybe there's a library of basic string functions
somewhere you could link to on the string page.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=447475&aid=954984&group_id=46815


-------------------------------------------------------
This SF.Net email is sponsored by: SourceForge.net Broadband
Sign-up now for SourceForge Broadband and get the fastest
6.0/768 connection for only $19.95/mo for the first 3 months!
http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click