Skip navigation
Currently Being Moderated

Find the next word in the paragraph

May 1, 2012 6:52 AM

I have a series of "key words" formatted with a particular Character Style. I am using this to find the words:

 

var doc = app.activeDocument;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findTextPreferences = app.findTextPreferences = null;
app.findGrepPreferences.appliedCharacterStyle = "HMI";

var hmiText = app.activeDocument.findGrep();
alert (hmiText.length);

 

This is working fine. For each found word, I do a look up in an XML file to find its replacement. Then I replace the found word with its replacement. Now I have to do something else that has me stuck. Each word I am replacing has a following word or words in parenthesis. I have to find these and delete them. So, an example would be this:

 

This is the term (word or words) that I am replacing.

 

I am finding and replacing "term" with its equivalent from the spreadsheet. But now I have to find "(word or words)" directly following and delete it. When I am done with my find/change, I am usually left with a TextStyleRange or a Word. Given this, I want to find the next word or phrase within parenthesis. Any pointers would be appreciated. Thanks.

 

Rick Quatro

 
Replies
  • Currently Being Moderated
    May 1, 2012 3:44 PM   in reply to frameexpert

    Hi,

     

    If "Each word You are replacing has a following word or words in parenthesis"

    then it should be possible to remove all characters using

    myStory.characters.nextItem(hmiText[i].characters[-1])

    inside a loop while(myStory.characters.nextItem(hmiText[i].characters[-1]).contents !== ")" )
    first

    and do proper find change

    after

     

    hopefully...

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points