Skip to main content
Inspiring
December 4, 2018
Answered

Change Line-Breaks in Paragraphs by GREP/regex

  • December 4, 2018
  • 1 reply
  • 1152 views

Here is my Problem:
A Text set in CS6 uses a different character for Line-Breaks as CC.
Now there is the idea to run a script in CC2019 to convert Forced-Line-Breaks in Paragraphs via GREP/regex.

This code works, but not for those Line-Breaks. I didn't figure out the character.

// regex_changeContentsOfWordOrString_RemainFormatting.jsx   
// regards pixxxel schubser   
/* var s = /(\r\n|\r|\n)/; */ 
/* var s = /\u000D/; */ 
/* var s = /\u000C/; */ 
/* var s = /^n/; */ 
var s = /\n/;
/* var s = /\u000A/; */
/* var s = /\u000D/; */
/* var replacer = "hello", result; */
/* var replacer = "bla", result; */  
/* var replacer = "\r", result; */
var replacer = /\r/, result; 
var atf = activeDocument.textFrames[0];     
while (result = s.exec(atf.contents)) {
       try {
           aCon = atf.characters[result.index];
           aCon.length = result[0].length;
           aCon.contents = replacer;
           } catch (e) {};
       }

Which character is it?

And here is the download-link for the test-file:
BlocksatzCS6.ai

Changed Line-Endings

This topic has been closed for replies.
Correct answer renél80416020

Salut !

var s = new RegExp(String.fromCharCode(3), "g");

  var replacer = "\r",  //  or var replacer = "\n",

      result;

  var atf = activeDocument.textFrames[0];

    while (result = s.exec(atf.contents)) {

      try {

          aCon = atf.characters[result.index];

          aCon.length = result[0].length;

          aCon.contents = replacer;

        } catch (e) {};

    }

de elleere LR

1 reply

renél80416020
renél80416020Correct answer
Inspiring
December 6, 2018

Salut !

var s = new RegExp(String.fromCharCode(3), "g");

  var replacer = "\r",  //  or var replacer = "\n",

      result;

  var atf = activeDocument.textFrames[0];

    while (result = s.exec(atf.contents)) {

      try {

          aCon = atf.characters[result.index];

          aCon.length = result[0].length;

          aCon.contents = replacer;

        } catch (e) {};

    }

de elleere LR

AndyWizzAuthor
Inspiring
December 6, 2018

Thanks alot, this works!!!
Merci beaucoup de votre aider!!!