So you could look into this page here:
https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-8543549B-F0D7-43CD-87A3-F6B827FF0B88
which gives the string functions. Perhaps use:
(strlen [string ...]) to find the length of the text string
(vl-string-search pattern string [ start-pos]) to find the position of the first '-' and from calculate the variable 'len' in the code above and go from there.
As an alternative I use Lee Macs String to List (http://lee-mac.com/stringtolist.html#:~:text=%3B%3B String to List - Lee Mac %3B%3B,str (%2B pos len)))) (reverse (cons str lst)))) to split the text strings into parts, then remake the string using the parts and changing them as required. I quite like this way since you can change any part of the text between any deliminators - even multiple changes easily.
Something like this: Should be quite versatile to do all the above, variable lengths, suffix and prefix,
(defun c:Testthis ( / Prefix Suffix presuf ss acount MyNewString MyEnt MyString MyList MyCount MyNewString)
(setq Prefix "Prefix TExt") ; change these texts as required or
;;(setq Prefix (getstring T "\nEnter Prefix Text:"))
(setq Suffix "Suffix Text")
;;(setq Suffix (getstring T "\nEnter Suffix Text:"))
;;Sub Functions
(defun LM:str->lst ( str del / pos )
(if (setq pos (vl-string-search del str))
(cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
(list str)
)
)
(initget "pre suf both")
(setq presuf (strcase (getkword "\nEnter an option (Pre/Suf/both): ") )) ; Select change to make
(setq ss (ssget '((0 . "*TEXT"))) ) ; Select text, mtext, rtext
(setq acount 0)
(while (< acount (sslength ss)) ; loop through selection
(setq MyNewString "") ; empty text string
(setq MyEnt (entget (ssname ss acount)) )
(setq MyString (cdr (assoc 1 MyEnt))) ; Gets text strinbg (up to 1st ~500 characters)
(setq MyList (LM:str->lst MyString "-")) ; text to list
;;Modify list items, could use cond here
(if (= presuf "PRE") (setq MyList (subst Prefix (nth 0 MyList) MyList ) ) )
(if (= presuf "SUF") (setq MyList (subst Suffix (nth 0 (reverse MyList)) MyList ) ) )
(if (= presuf "BOTH")
(progn
(setq MyList (subst Prefix (nth 0 MyList) MyList ) ) ; Change Prefix text as you want
(setq MyList (subst Suffix (nth 0 (reverse MyList)) MyList ) ) ; change Suffix text as you want
)
)
;;Remake text from list
(setq MyNewString (nth 0 MyList))
(setq MyCount 1)
(while (< MyCount (length MyList))
(setq MyNewString (strcat MyNewString "-" (nth MyCount MyList)))
(setq MyCount (+ MyCount 1))
) ; end while
(entmod (subst (cons 1 MyNewString) (assoc 1 MyEnt) MyEnt )) ; update text
(setq acount (+ acount 1))
) ; end while
(princ)
)