• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Find and replace with wildcards in framemaker.

Community Beginner ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

Hi,

How to find 5 digits value with comma (10,000) and replace 5 digits with dot (10.000) and space (10 000) using wildcard for framemaker using extendscript ? Please suggests if any ideas.

Thank You.

TOPICS
Scripting

Views

850

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

I am pressed for time this morning, but I will give you a little code to get you started. Here is the basic way to do it with a regular expression:

var text, regex;

text = "How to find 5 digits value with comma (10,000) and 15,000.";

regex = /(\d+),(\d+)/g;

if (regex.test (text) === true) {

    text = text.replace (regex, "$1.$2");

    alert (text);

}

I assume you are doing this in the context of FrameMaker text so things are more complicated. Do you know how to use the Find method on the Doc object? If so, there is a way to do finds using regular expressions like you can in the FrameMaker interface. Here is how you can set up your Find parameters using regular expressions:

function getRegexFindParams (regex) {

   

    findParams = new PropVals ();

    propVal = new PropVal ();

    propVal.propIdent.num = Constants.FS_FindText;

    propVal.propVal.valType = Constants.FT_String;

    propVal.propVal.sval = regex;

    findParams[0] = propVal;

   

    propVal = new PropVal ();

    propVal.propIdent.num = Constants.FS_FindCustomizationFlags;

    propVal.propVal.valType = Constants.FT_Integer;

    propVal.propVal.ival = 16; // Regular expressions

    findParams[1] = propVal;

   

    propVal = new PropVal ();

    propVal.propIdent.num = Constants.FS_FindWrap;

    propVal.propVal.valType = Constants.FT_Integer;

    propVal.propVal.ival = 0;

    findParams[2] = propVal;

   

    propVal = new PropVal ();

    propVal.propIdent.num = Constants.FS_RegexFlavour;

    propVal.propVal.valType = Constants.FT_Integer;

    propVal.propVal.ival = 1; // Perl compatible

    findParams[3] = propVal;

    return findParams;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

LATEST

Thank you.i have followed this code.

   var doc=app.ActiveDoc

    var docStart = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf ; 

    var tloc = new TextLoc (docStart, 0); 

    var searchString ="[1-9][0-9],[0-9][0-9][0-9]";

    var replaceString = "$1.$2";   

    // setup find parameters 

   findParams = AllocatePropVals(2); //"initializes the pointer"

    findParams[0].propIdent.num = Constants.FS_FindCustomizationFlags;

    findParams[0].propVal.valType = Constants.FT_Integer;   

    findParams[0].propVal.ival = Constants.FF_FIND_USE_WILDCARDS;

    findParams[0].propVal.ival = 4;   

    findParams[1].propIdent.num = Constants.FS_FindText;

    findParams[1].propVal.valType = Constants.FT_String;

    findParams[1].propVal.sval = searchString;

   var foundText = doc.Find(tloc, findParams);

   pgfFmt = doc.GetNamedPgfFmt ("chsubpara5");

   var props = pgfFmt.GetProps();  

  var counter = 0

while (foundText.beg.obj.ObjectValid()&& counter < 100) {      

      tloc = new TextLoc(foundText.end.obj, foundText.end.offset);

      var pgf = tloc.obj;

      pgf.SetProps (props);

      doc.AddText (tloc, replaceString); 

      foundText = doc.Find(tloc, findParams); 

     doc.DeleteText (foundText);

      alert(foundText);

      counter ++;

   }

Doesn't work in wildcards in framemaker.I need Find and Replace work while using wildcards in framemaker.So please suggests if any ideas.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines