替换字符串中同一单词的一个或多个实例,可能是这样的
- (defun c:test (/ I NSTRL NWRD OSTRL OWRD STR STRBASE)
- (if
- (and (setq str (getstring T "\nPlease type your sentense: "))
- (not (= str ""))
- (setq owrd (getstring T "\nType the word you want to replace: "))
- (not (= owrd ""))
- (setq nwrd (getstring T "\nType the word you want to replace with: "))
- (wcmatch str (strcat "*" owrd "*"))
- );; and
- (progn
- (setq nstrl (strlen nwrd)
- ostrl (strlen owrd)
- i 1
- );; setq
- (while (= ostrl (strlen (setq strbase (substr str i ostrl))))
- (if (= strbase owrd)
- (setq str (strcat (substr str 1 (1- i)) nwrd (substr str (+ i ostrl))))
- );; if
- (setq i
- (if (= strbase owrd)
- (+ i nstrl)
- (1+ i)
- );; if
- );; setq
- );; while
- (prompt (strcat "\nNew string is: " str))
- );; progn
- (princ "\nMatch not found! ")
- );; if
- (princ)
- );; test
HTH公司
亨里克 |