1 Reply Latest reply on May 1, 2012 3:44 PM by Jump_Over

    Find the next word in the paragraph

    frameexpert Level 4

      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

        • 1. Re: Find the next word in the paragraph
          Jump_Over Level 5



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

          then it should be possible to remove all characters using


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

          and do proper find change