addslashes (sort of)
Sort of addslashes type method; nothing special figured it may be useful at some point to someone.EDIT:
Yeah that was a bit off; amended code below
;;-Ollie;;Precede each instance of an identifying char (single|group) within the source;string with a char (single|group);;text = (String) source string;iinsert = (String) text to insert in front of matches;identifier = (String) text to be preceded by the insert text in the source string(defun addMidText(text insert identifier / i ids textLen idLen insertionLen) (setq i0) (setq textLen (strlen text)) (setq idLen(strlen identifier)) (setq insertLen (strlen insert)) (while(< (setq i (1+ i))(- textLen idLen)) (if(eq (substr text i idLen) identifier) (progn (setq text (strcat (substr text 1 (1- i)) insert (substr text i (- textLen (1- i))))) (setq i (+ iinsertLen) textLen(+ textLen insertLen )) ) )) text)Cheers,
Ollie. On first testing, I couldn't get it to function, but I may have used it incorrectly,
However, what about vl-string-subst?
Or for multiple instances:
(defun StringSubst ( new old str ) ;; © Lee Mac 2010 ( (lambda ( i / nl ) (setq nl (strlen new)) (while (and (< i (strlen str)) (setq i (vl-string-search old str i)) (setq str (vl-string-subst new old str i) i (+ i nl)) ) ) str ) 0 ))
页:
[1]