[英]Google Apps Script replaceText() not working with apostrophe " ' "
在我的代码中,当我尝试用“不”替换“不”时,它不起作用,但是当我使用常规词时,它起作用。 我试图用“不要”来逃避。 有没有一种特殊的方法可以在谷歌应用程序脚本中转义字符?
//Sidebar.html
function doWordReplace(value) {
if(value.checked) {
google.script.run.withSuccessHandler(print).wordReplace("don't");
}
else {}
}
//Replace.gs
function wordReplace(findMe) {
var text = DocumentApp.getActiveDocument().getBody().editAsText();
text.replaceText(findMe, "do not");
return "replacement successful";
}
使用replace()而不是replaceText()
function wordReplace(findMe) {
var text = DocumentApp.getActiveDocument().getBody().getText();
// Use Unicode for right single quotation mark
// \u2018-left single, \u2019-right single, \u0027-apostrophe
text.replace(/don\u2019t/gi, "do not");
DocumentApp.getActiveDocument().getBody().setText(text);
return "replacement successful";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.