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

switch numbers comma-dot and viceversa

New Here ,
Sep 01, 2014 Sep 01, 2014

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.contents.replace (/,/g, "#");

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

  Found.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.contents.replace (/,/g, "#");

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

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

         //alert(Temp);

  }

TOPICS
Scripting
4.1K
Translate
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

correct answers 1 Correct answer

LEGEND , Sep 06, 2014 Sep 06, 2014

Hi Cinzia,

As I told you in private, I think this grep code is better. Only this line to change:

app.findGrepPreferences.findWhat = /^-*[\d,.]+\d/.source;

Translate
New Here ,
Apr 03, 2025 Apr 03, 2025
LATEST

Hi Obi,

 

Can you help me out, I have a big file with a loto of numbers for example 1 000 000 or 1000 or 1 000, were differente people writing the document what I want if to make a grep that find all these kind of formating and change the space or the non space to a dot, to get this result 1.000.000 or 1.000 or 1.000. Basically I want to format them to the European version of number formating, where the is dots between the thousands separator. Can you please help me out. Much appreciated.

Translate
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