In this code
i have a function that reads a txt file and makes a list of its contents.
then i have a function that searches that list for a specific word.
when that word is found im trying to get it to remove that word and replace it with another word without it changing its position in the list
i think im on the right track however its wiping out the whole list just for the word im trying to replace it with
can anyone guide me in the right direction on how i can replace an nth in a list without destroying the whole list
ill eventually have to write it back to a text file but i think i have that one covered with a foreach function
thanks for any help
(defun readfile (filename / f path line lst)
(if (setq path (strcat (getvar "Dwgprefix")
(vl-Filename-Base (vl-Filename-Directory (getvar "Dwgprefix")))
" Dwg List.txt"
)
)
(cond
((setq f (open path "r"))
(while (setq line (read-line f))
(setq lst (cons line lst))
)
(close f)
(reverse lst)
)
)
)
)
(if (setq lst (readfile path))
(progn
(setq avar (nth 0 lst))
(defun wcmatch_first ( lst pattern flag / result )
(setq pattern (if flag (strcase pattern) pattern))
(vl-some
'(lambda (str) (if (wcmatch str pattern) (setq result str)))
(if flag (mapcar 'strcase lst) lst)
)
result
)
(progn
(if (setq item (wcmatch_first lst (strcat "*" old_title "*") nil)) ; change this for search word
(progn
(setq o_var (vl-position item lst))
(setq lst1 (vl-string-subst "hello" (nth o_var lst) (nth o_var lst)))
)
)
)
)
(alert "no")
(progn
;; if file doesnt exist
; (do other)
)
)