Use MUNGER with styled text
I did a little more study of your code after sending my earlier post, and I think I have identified the problem. FN Munger (a toolbox call) doesn't know about ZTXT handles (an FB construct). It can "munge" them alright, and adjust the handle size in the process, but it doesn't know anything about resetting the length word. I think this might work to reset it (call after FN MUNGER)...
& [EFHandle&], FN GETHANDLESIZE(EFHandle&)-2 'poke new size...but only if there is no style info appended to the ZTXT handle.
Macsbug shows that your function is working correctly, it just doesn't get the length word reset. Try the above and see if that works. If not, you may need to calculate the change in handle size (getting it before and after) so you can adjust your length word accordingly.
BTW, unless you _need_ a ZTXT handle to move into another field, I would say you'd be ahead just to use the efH&..teTextH& that I mentioned, but you do need the call to TECALTEXT.
This FN works in your code:
LOCAL FN findReplace DIM a$, b$, a DIM theString$ DIM EFHndl&,txtH& '--- make string theString$ = "aaa*bbb*ccc*ddd*eee*fff*ggg*hhh*iii* EDIT$(1) = theString$ '--- replace the string with new string a$ = "ccc" b$ = "ZZZZZZZZZ" CALL MOVETO (0,60) PRINT " Text: ";a$; " has been replaced by: ";b$ PRINT " Note the content of the new string" PRINT " Q: Where are the end characters (h*iii*) if" PRINT " Munger is supposed to adjust Handle size?" PRINT PRINT " Press command period to break..." GET FIELD EFHndl&,1 '*** get ZTXT handle for edit field EDIT$(2) = &EFHndl& 'copy it into field 2 DEF DISPOSEH(EFHndl&) '*** dispose of ZTXT handle EFHndl& = TEHANDLE(2) 'get TE handle txtH& = EFHndl&..teTextH& 'get text handle a = FN FindReplaceString&(txtH&,0,a$,b$)'use munger CALL TECALTEXT(EFHndl&) 'recalculate field info CALL INVALRECT(#[EFHndl&]+_teViewRect) 'force redraw EDIT FIELD 0 END FN