1 Reply Latest reply on Nov 23, 2008 6:21 AM by [Jongware]

    [JS][CS2]Find/Change loop

    Level 1
      Hello Scripters,

      I need to find a specific character style in my document then process its content and replace it with the processed content. How can i make a loop so that it process all of the instances of that style?

      To make the picture clearer, let's say I'm gonna search for all the superscripted then let's say remove the commas in it and sort it.

      i got it right but it only replace the first intance. how can i make a loop so it process all the instances of that character style.

      app.findPreferences.appliedCharacterstyle = 'mySup';
      var mySearch = app.activeDocument.search('');
      for (i=0; i>mySearch.length; i++)
      var myResult = myFunction();
      app.activeDocument.search( "whatDoIPutHere?", false, false, myResult );

      help please...
        • 1. Re: [JS][CS2]Find/Change loop
          [Jongware] Most Valuable Participant
          You have got the wrong idea about the Search function. It finds *everything*, and it returns an array of all found items. You don't have to search again.

          With that out of the way :-) if your function 'myFunction' does something to the text that changes its length (you mention removing comma's), the array of found items is no longer valid, because it points to character indexes from the start of the document. (I guess.) The advocated way of handling this is to start processing at the
          b end
          of the 'found' array, so any manipulations will not mess up the rest. I.e.,

          for (i=mySearch.length-1; i >=0; i--)
              var myResult = myFunction();