That's a easy fix, ta.
(defun c:test ( / MyEnt MyEntGet MyTExt MyStart OldNumber NewNumber NewText)
(vl-load-com)
(setq MyEnt (car (entsel "\nSelect Text")))
(while ;; while loop, checking that text was selected
(and
(/= (cdr (assoc 0 (entget MyEnt))) "TEXT")
(/= (cdr (assoc 0 (entget MyEnt))) "MTEXT")
)
(princ "\nWell, that isn't text is it now? ")
(setq MyEnt (car (entsel "Please select Text")))
)
(setq MyEntGet (entget MyEnt)) ; get text entity definition
(setq MyText (cdr (assoc 1 MyEntGet))) ; get text string
(setq MyStart (vl-string-search "-" MyText)) ; look for first instance of "-" in text string. Error check it exists?
(setq NewNumber (getstring "\nEnter New Number : " t)) ; ask for replacement number, t to allow for spaces in text
(if (wcmatch MyText "*#`-#*") (setq OldNumber (substr MyText (- MyStart 0) 3))) ; for 0-0 to 9-9
(if (wcmatch MyText "*##`-##*") (setq OldNumber (substr MyText (- MyStart 1) 5))) ; for 10-10 to 99-99
(if (wcmatch MyText "*###`-###*") (setq OldNumber (substr MyText (- MyStart 2) 7))) ; for 100-100 to 999-999
(if (wcmatch MyText "*# `- #*") (setq OldNumber (substr MyText (- MyStart 1) 5))) ; for 0-0 to 9-9
(if (wcmatch MyText "*## `- ##*") (setq OldNumber (substr MyText (- MyStart 2) 7))) ; for 10-10 to 99-99
(if (wcmatch MyText "*### `- ###*") (setq OldNumber (substr MyText (- MyStart 3) 9))) ; for 100-100 to 999-999
(if (= OldNumber nil) ; if text contained a valid format, update text
(princ "Text string does not contain 'xx-xx' format text. Going for a nap now.")
(progn
(if (wcmatch MyText "*#`-#*")
(setq NewText (vl-string-subst (strcat NewNumber "-" NewNumber) OldNumber MyText)) ; substitute new text in
(setq NewText (vl-string-subst (strcat NewNumber " - " NewNumber) OldNumber MyText)) ; substitute new text in
)
(vla-put-TextString (vlax-ename->vla-object MyEnt) Newtext)
)
)
(princ) ; exit quietly
)