Highlighted

Find and Replace script

Explorer ,
Sep 19, 2020

Copy link to clipboard

Copied

Hi,

I'm just trying to replace multiple words but unfortunately only first word in findWhat is replacing with first word in changeTo 

 

For example: in the below script only January is changing with April and rest of months are not changing accordingly, please do help me in changing February with May, March with June so on

 

var myDoc = app.activeDocument

app.findTextPreferences = NothingEnum.nothing;

app.changeTextPreferences = NothingEnum.nothing;

app.findTextPreferences.findWhat = "January", "February", "March", "July", "August", "September"; app.changeTextPreferences.changeTo = "April", "May", "June", "October", "November", "December"; app.activeDocument.changeText ();

 

Thank you!

Adobe Community Professional
Correct answer by rob day | Adobe Community Professional

If you are having trouble with Manan’s loop, which depends on matching arrays, maybe try a function and call it for each F&C that you need:

 

textSearch("January", "April");
textSearch("February", "May");
textSearch("March", "June");
textSearch("July", "October");
textSearch("August", "November");
textSearch("September", "December");


function textSearch(f,c){
    app.findTextPreferences.findWhat=NothingEnum.NOTHING
    app.changeTextPreferences.changeTo=NothingEnum.NOTHING
    app.findTextPreferences.findWhat = f;
    app.changeTextPreferences.changeTo = c;
    app.activeDocument.changeText( )
}
TOPICS
Scripting

Views

91

Likes

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

Find and Replace script

Explorer ,
Sep 19, 2020

Copy link to clipboard

Copied

Hi,

I'm just trying to replace multiple words but unfortunately only first word in findWhat is replacing with first word in changeTo 

 

For example: in the below script only January is changing with April and rest of months are not changing accordingly, please do help me in changing February with May, March with June so on

 

var myDoc = app.activeDocument

app.findTextPreferences = NothingEnum.nothing;

app.changeTextPreferences = NothingEnum.nothing;

app.findTextPreferences.findWhat = "January", "February", "March", "July", "August", "September"; app.changeTextPreferences.changeTo = "April", "May", "June", "October", "November", "December"; app.activeDocument.changeText ();

 

Thank you!

Adobe Community Professional
Correct answer by rob day | Adobe Community Professional

If you are having trouble with Manan’s loop, which depends on matching arrays, maybe try a function and call it for each F&C that you need:

 

textSearch("January", "April");
textSearch("February", "May");
textSearch("March", "June");
textSearch("July", "October");
textSearch("August", "November");
textSearch("September", "December");


function textSearch(f,c){
    app.findTextPreferences.findWhat=NothingEnum.NOTHING
    app.changeTextPreferences.changeTo=NothingEnum.NOTHING
    app.findTextPreferences.findWhat = f;
    app.changeTextPreferences.changeTo = c;
    app.activeDocument.changeText( )
}
TOPICS
Scripting

Views

92

Likes

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
Sep 19, 2020 0
Adobe Community Professional ,
Sep 19, 2020

Copy link to clipboard

Copied

Hi Sunil,

I had already shared a similar script for you in the past, see this

Making some changes in that script should work for this requirement as well. Do the following changes and then try

  • Set findWhat to fullName[i]
  • Set changeTo to shortName[i]

-Manan

Likes

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
Reply
Loading...
Sep 19, 2020 1
Explorer ,
Sep 21, 2020

Copy link to clipboard

Copied

Thank you, Manan!

 

Script which you have shared earlier was working fine, new one which I have posted doesn't work well and in fact the changes which you have suggested didn't work probably I might have missed somewhere. 

 

Script posted Rob Day worked well...

Likes

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
Reply
Loading...
Sep 21, 2020 0
Adobe Community Professional ,
Sep 20, 2020

Copy link to clipboard

Copied

If you are having trouble with Manan’s loop, which depends on matching arrays, maybe try a function and call it for each F&C that you need:

 

textSearch("January", "April");
textSearch("February", "May");
textSearch("March", "June");
textSearch("July", "October");
textSearch("August", "November");
textSearch("September", "December");


function textSearch(f,c){
    app.findTextPreferences.findWhat=NothingEnum.NOTHING
    app.changeTextPreferences.changeTo=NothingEnum.NOTHING
    app.findTextPreferences.findWhat = f;
    app.changeTextPreferences.changeTo = c;
    app.activeDocument.changeText( )
}

Likes

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
Reply
Loading...
Sep 20, 2020 1