[英]ExtendScript search/replace loop
I am using ExtendScript
with InDesign to have some simple search and replace to change a GREP
. 我正在将
ExtendScript
与InDesign一起使用,以进行一些简单的搜索和替换以更改GREP
。
If I write them out one by one everything works fine. 如果我一一列出,一切都会很好。
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findChangeGrepOptions = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '^~8 ';
app.changeGrepPreferences.changeTo = `~8\\t`;
myDoc.changeGrep();
But I want to tidy things up and create a loop that runs two arrays containing the search and the find. 但是我想整理事情并创建一个循环,该循环运行包含搜索和查找的两个数组。
var findWhat = [ '^~8 ', '^·( |\\t)', '~S', '^ +', ' +$', ' +', '~P', '^\\t+(?=\\r)', '\\n', '\\r\\r\\r+'];
var changeTo = ['~8\\t','~8\\t',' ', '','',' ','\\r','','\\r','\\r\\r'];
for(var i = 0; i < findWhat.lenght; i++){
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findChangeGrepOptions = NothingEnum.nothing;
app.findGrepPreferences.findWhat = findWhat[i];
app.changeGrepPreferences.changeTo = changeTo[i];
myDoc.changeGrep();
}
This doesn't give me an error but it doesn't change anything either. 这不会给我一个错误,但也不会更改任何内容。 Is there a way to have some kind of error handling of notation set that can provide me with some information?
有没有一种方法可以对符号集进行某种错误处理,从而为我提供一些信息?
I'm edditing the code in ExtendScript Toolkit
我正在编辑
ExtendScript Toolkit
的代码
I found my own embarrassing solution. 我找到了自己的尴尬解决方案。
The loop doesn't loop because it doesn't understand what lenght
means. 循环不会循环,因为它不了解
lenght
含义。
Changed it to length
and it runs fine...... 将其更改为
length
,并且可以正常运行……
var findWhat = [ '^~8 ', '^·( |\\t)', '~S', '^ +', ' +$', ' +', '~P', '^\\t+(?=\\r)', '\\n', '\\r\\r\\r+'];
var changeTo = ['~8\\t','~8\\t',' ', '','',' ','\\r','','\\r','\\r\\r'];
for(var i = 0; i < findWhat.length; i++){
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findChangeGrepOptions = NothingEnum.nothing;
app.findGrepPreferences.findWhat = findWhat[i];
app.changeGrepPreferences.changeTo = changeTo[i];
myDoc.changeGrep();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.