[cl-cookbook-contrib] [ cl-cookbook-Feature Requests-954984 ] String section addition
Brought to you by:
jthing
From: SourceForge.net <no...@so...> - 2004-05-16 21:38:45
|
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 |