This should work
;; settings
(setq alz_digits 2) ;; number of digits
;; substring, like php substr
;; Just because I don't like (substr) enough
(defun substring ( str idx len )
(substr str (if (< idx 0) (+ 1 (strlen str) idx) (1+ idx)) len)
)
(defun alze (val delim digits / pos rest num numlength)
;; example: (vl-string-position (ascii "z") "azbzlmnqc" nil T)
(setq pos (vl-string-position (ascii delim) val nil T)) ;; the last "-" is on this string position
(setq rest (substring val 0 (+ pos 1))) ;; the rest of the string, including the last -
(setq num (substring val (+ pos 1) (strlen val))) ;; the number. I don't really care if it's a number, I'll just add a zero if the string length is < digits
(repeat (- digits (strlen num))
(setq num (strcat "0" num)) ;; add zeroes to num as long as num has fewer characters as digits
)
(strcat rest num) ;; now stick rest back to num
)
;; Add Leading Zero End
(defun c:alze ( / ss i elm val newval)
(setq ss (ssget '((0 . "*TEXT"))))
(setq i 0)
(repeat (sslength ss)
(setq elm (ssname ss i))
;; text value
(setq val (cdr (assoc 1 (entget elm))))
;;
(setq newval (alze val "-" alz_digits))
(entmod (subst (cons 1 newval) (cons 1 val) (entget elm)))
(setq i (+ i 1))
)
(princ)
)