Skip to main content
LindseyB07
Participating Frequently
February 21, 2019
Answered

Find and replace text SCRIPT

  • February 21, 2019
  • 2 replies
  • 10835 views

I have been trying to find a scrip that will help me replace a Hard return. This will not work with the menu action. Is any one able to help me. Im not the greatest at coding, I know a little but not enough to right this.

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

you did give me a solution and i am still trying to figure out how to make it work.


    lindseybock123  Réfléchir tu sais faire ?

Avec le script de CarlosCanto

// JavaScript Document for Illustrator
var active_doc = app.activeDocument;

var search_string = /\r/g; // g for global search, remove i to make a case sensitive search
var replace_string = String.fromCharCode(3); // pour "\n"

var text_frames = active_doc.textFrames;
var this_text_frame, this_text_frame;

if (text_frames.length > 0) {
    for (var i = 0 ; i < text_frames.length; i++) {
          this_text_frame = text_frames[i];
          new_string = this_text_frame.contents.replace(search_string, replace_string);
          this_text_frame.contents = new_string;
    }
}

elleere LR Pour vous servir...

2 replies

LindseyB07
Participating Frequently
February 21, 2019

Code i found that will work

var active_doc = app.activeDocument; 

 

var search_string = /\r/gi; // g for global search, remove i to make a case sensitive search 

var replace_string = "~"; 

 

var text_frames = active_doc.textFrames; 

 

if (text_frames.length > 0) 

    for (var i = 0 ; i < text_frames.length; i++) 

      { 

          var this_text_frame = text_frames[i]

           var new_string = this_text_frame.contents.replace(search_string, replace_string); 

            

           if (new_string != this_text_frame.contents) 

               { 

                    this_text_frame.contents = new_string; 

               } 

      } 

CarlosCanto
Community Expert
Community Expert
February 22, 2019

this code seemed very familiar, so I searched and digged the original out of the grave

Re: Illustrator Find And Replace

are you good then? or do you still need help?

LindseyB07
Participating Frequently
February 22, 2019

That is the same code that i found. I am good with this I can make that work. If there is any chance you know how to make \n (Forced line break) I would be very grateful. I cant seem to get it to work. not sure what i am doing wrong.

LindseyB07
Participating Frequently
February 21, 2019

Sorry about my typos. I was typing to fast

pixxxelschubser
Community Expert
Community Expert
February 21, 2019

Give an example *.AI file for testing please.

renél80416020
Inspiring
February 21, 2019

I am not sure how to up load a file on here but im just trying to replace the line brake you get when you hit the "Enter" Button.

if you copy and past this in to a

AI file there will be a few in here

..


Salut

remplacer "\r" par quoi ?

LR