Reu,
Your code was close but did not work correctly.
Revised code below:
;;; Function (C:MCHAR) ;
;;; Description: This program is to remove a number of characters from the end ;
;;; of a text string and place them at the beginning of a 2nd string. ;
(defun c:mchar (/ #chrs ss1 ss2 entlst1 entlst2 txt1 txt2 str)
(and
(princ "\nAppend characters from 1st text to the 2nd text.")
; Print message to tell user what the program does.
(setq #chrs (getint "\nHow many characters do you want to move? "))
; Set variable "#chars" to user defined number of characters to move.
(princ "\nSelect the 1st Text to get chars.")
; Print message to tell user what to do.
(setq ss1 (ssget "_:S" '((0 . "TEXT"))))
; Set variable "ss1" to the user defined text object to move characters from.
(setq entlst1 (entget (ssname ss1 0)))
; Set variable "entlst1" to the association list of the user defined text to move characters from.
(setq txt1 (cdr (assoc 1 (entget (ssname ss1 0)))))
; Set variable "txt1" to the text string of the user defined text to move characters from.
(princ "\nSelect the Text to add chars to.")
; Print message to tell the user what to do.
(setq ss2 (ssget "_:S" '((0 . "TEXT"))))
; Set variable "ss2" to the user defined text object to move characters to.
(setq entlst2 (entget (ssname ss2 0)))
; Set variable "entlst2" to the association list of the user defined text to move the characters to.
(setq txt2 (cdr (assoc 1 (entget (ssname ss2 0)))))
; Set variable "txt2" to the text string of the user defined text to move characters from.
(setq str (substr txt1 (1+ (- (strlen txt1) #chrs))))
; Set variable "str" to the text string to be moved from 1st text to 2nd text.
(entmod ; update the following entity list
(subst ; make some changes to the list "entlst2"
(cons 1 (strcat str " " (cdr (assoc 1 entlst2))))
; new string + 'space character' + dxf 1
(assoc 1 entlst2) ; old string with DXF code "1"
entlst2 ; original entity association list
) ;_end subst
) ;_end entmod
(entmod
(subst ; make some changes to the list "txt1"
(cons 1 (substr txt1 1 (- (strlen txt1) #chrs))) ; <-----<<< CAB changed this
; "txt1" - ("#chars" + 3)
(assoc 1 entlst1) ; old string with DXF code "1"
entlst1 ; original entity association list
) ;_end subst
) ;_end entmod
) ;_end and
(princ "\nType MCHAR to invoke.")
(princ)
) ;_end defun