24 Replies Latest reply on Sep 6, 2014 2:21 AM by Obi-wan Kenobi

    switch numbers comma-dot and viceversa

    cinzia_pn Level 1

      hello

       

      I have this script that changes the numbers format from european to UK/US  (for example 1.000 to 1,000) and doesn’t apply to the numbers preceded by any letter.

       

      at the moment it partially works fine, changing only those numbers preceded by letters  without the space between them. for example: machine model TSK4.500 won’t be changed into TSK4,500 and that’s ok.

       

      I need  it to recognize and not change also those numbers preceded by letters with a space:

      TSK 4.500 must not be switched.

       

      So in few words, I need this script to work only with numbers avoiding those that might be part of a name etc.

       

      can someone please help me?

      thank you very much

      Cinzia

       

       

      try {main ()}

      catch (_){alert ("Can't run.")}

       

      function main (){

        function FindItems (){

        if (app.selection.length == 0) {return app.activeDocument.findGrep();}

        if (app.selection[0].hasOwnProperty ("baseline")) {return app.selection[0].findGrep();}

        if (app.selection[0] instanceof TextFrame) {return app.selection[0].parentStory.findGrep();}

        exit ();

        } // FindItems

       

        // BEGIN main

        app.findGrepPreferences = app.changeGrepPreferences = null;

        app.findGrepPreferences.findWhat = "\\d+[,.\\d]+\\d+";

          //app.findGrepPreferences.findWhat = "[?\\l\\u]+\\d+[,.\\d]";

          //app.findGrepPreferences.findWhat = "[![\\l\\u]]+\\d+[,.\\d]";

          //app.findGrepPreferences.findWhat = "\\d+[,.\\d]";

        var Found = FindItems ();

        var Temp;

        for (var i = Found.length-1; i >= 0; i--)

        {

        Temp = Found[i].contents.replace (/,/g, "#");

        Temp = Temp.replace (/\./g, ",");

        Found[i].contents = Temp.replace (/#/g, ".");

               //alert(Temp);

        }

            

              app.findGrepPreferences.findWhat = "[\\l\\u]+\\d+[,.\\d]";

          //app.findGrepPreferences.findWhat = "\\d+[,.\\d]";

        var Found = FindItems ();

        var Temp;

        for (var i = Found.length-1; i >= 0; i--)

        {

        Temp = Found[i].contents.replace (/,/g, "#");

        Temp = Temp.replace (/\./g, ",");

        Found[i].contents = Temp.replace (/#/g, ".");

               //alert(Temp);

        }