Example: I have a text frame on the active page with the contents "Test link"; it is a cross reference destination, and thus has the ":" hidden character at the beginning of it which is counted as a character in the string. If write the following to replace the word "link" with "new text" using the following code, the cross reference is broken and I do not get an option to update the link.
var myDoc = app.activeDocument;
var currentPage = app.activeWindow.activePage;
var textLink = currentPage.allPageItems;
var replaceThis = textLink.contents.slice(6);
textLink.contents = textLink.contents.replace(replaceThis, "new text");