How to insert text at specific position?
In a nutshell, i know exactly where my tab is by using indexOf to get the position of the tab I want.
The problem is I simply cannot find a way to replace the text at that point. Id like to replace "/t" (tab) with "~<\t" (thin space + tab).
Ive tried slicing and joining but it removes all my anchored images.
Ive tried selecting the tab location then using app.selection[0].changeGrep to replace the text but it only works on the first occurance. I'm stumped, what am I missing here?
var myFrames = app.activeDocument.textFrames;
//loop through frames
for (i=0; i < myFrames.length; i++) {
// get all paragraphs
var myParagraphs = myFrames.paragraphs.everyItem().getElements();
//loop through paragraphs
for (n=0; n < myParagraphs.length; n++) {
//get contents of paragraph
var myLine = myParagraphs
.contents; //find first tab
var tablocation=myLine.indexOf('\t');
//find next tab
var tablocation=myLine.indexOf('\t', tablocation+1);
//select this second tab
myParagraphs
.characters.itemByRange(tablocation,tablocation).select(SelectionOptions.REPLACE_WITH); // if tablocation is -1 skip it
if (tablocation > 1 ) {
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\t";
app.changeGrepPreferences.changeTo= "~<\\t";
app.selection[0].changeGrep();
}
}
}
