3 Replies Latest reply on Feb 8, 2016 6:08 AM by Russ Ward

    Entering carriage returns in extendscript

    brians42907181

      So, I've been able to fight my way up to a point to where I can search for a string, apply a para format, then replace the found string. Works great!  Thanks, Russ, for the assist...

       

      Now, does anyone know how to enter a carriage return as part of a find/replace? I've tried to just use "\r" and several combinations of that but can't figure it out. I need to find a specific text string, go to the end and enter a carriage return.

       

      Also, along similar lines, when using the find function in the UI, you can put \P (for beginning of the para) and other criteria (like \t for tab stop). Does anyone know how to use those features in script?

       

      Below is what I'm using for the search and apply formatting, just for sharing purposes, it works fine, just looking to extend features. It could probably be done a bit more elegantly, but if it works...

       

      //This is the chsubpara5 search and tag
          var doc=app.ActiveDoc
          var docStart = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf ; 
          var tloc = new TextLoc (docStart, 0); 
          var findParams = new PropVals();
         // setup find parameters 
          var searchString = "[1-9]*.*.*.*.*.*.*[0-9]";
         
          findParams = AllocatePropVals(2);
        
          findParams[0].propIdent.num = Constants.FS_FindCustomizationFlags;
          findParams[0].propVal.valType = Constants.FT_Integer;   
          findParams[0].propVal.ival = 4;
         
          findParams[1].propIdent.num = Constants.FS_FindText;
          findParams[1].propVal.valType = Constants.FT_String;
          findParams[1].propVal.sval = searchString;
           
         pgfFmt = doc.GetNamedPgfFmt ("chsubpara5");
         var props = pgfFmt.GetProps();
         var foundText = doc.Find(tloc, findParams);        
         var counter = 0
        while (foundText.beg.obj.ObjectValid()&& counter < 100) { 
                
          tloc = new TextLoc(foundText.end.obj, foundText.end.offset);

      //alert (foundText.beg.offset, 2);
         if (foundText.beg.offset=="0")
         {
         var pgf = tloc.obj;
         pgf.SetProps (props);
         //doc.AddText (tloc, replaceString);
         doc.DeleteText (foundText);
            }    
            
          foundText = doc.Find(tloc, findParams);
          counter ++;
          }
      //End of chsubpara5 search and tag

        • 1. Re: Entering carriage returns in extendscript
          frameexpert Level 4

          The easiest thing might be to just add a new paragraph after the current one.

           

          var pgf = foundText.beg.obj;

          var newPgf = doc.NewSeriesPgf (pgf);

           

          -Rick

          • 2. Re: Entering carriage returns in extendscript
            Mike-Hardy Level 3

            I've not time to check this, but if a search string has a backslash, that backslash might be consumed by the compiler or interpreter. Try a double backslash, e.g. "\\PStart of a line".

             

            Note also that there are new find properties and values for regular expressions. These don't appear in the FDK documentation:

             

            #define FS_FindCustomizationFlags 15 /* IntT the following ored together */

            ...

            #define FF_FIND_USE_REGEX ((IntT) 0x10)

             

            #define FS_RegexFlavour 17 /*Enum one of the following*/

            #define FR_USE_PERL 1 /*Use perl flavour*/

            #define FR_USE_GREP 2 /*Use grep flavour*/

            #define FR_USE_EGREP 3 /*Use egrep flavour*/

            • 3. Re: Entering carriage returns in extendscript
              Russ Ward Level 4

              Hi Brian,

               

              I find that the newline escape sequence (\n) inserts a carriage return. As in:

               

              replaceString = "Some whole new paragraph.\n";

               

              Note, however, that I don't know that this is the "correct" way to do it. Sometimes incorrect methods introduce weird, hidden characters into a doc. My suspicion, though, is that this technique is OK.

               

              Russ