Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google Apps脚本replaceText()不使用撇号'&引用;_Javascript_Regex_String_Google Apps Script - Fatal编程技术网

Javascript Google Apps脚本replaceText()不使用撇号'&引用;

Javascript Google Apps脚本replaceText()不使用撇号'&引用;,javascript,regex,string,google-apps-script,Javascript,Regex,String,Google Apps Script,在我的代码中,当我试图用“不”替换“不”时,它不起作用,但当我使用常规单词时,它起作用。我试着用“不要”来逃避。 谷歌应用程序脚本中有没有特殊的字符转义方法 //Sidebar.html function doWordReplace(value) { if(value.checked) { google.script.run.withSuccessHandler(print).wordReplace("don't"); } else {} } //Replace

在我的代码中,当我试图用“不”替换“不”时,它不起作用,但当我使用常规单词时,它起作用。我试着用“不要”来逃避。 谷歌应用程序脚本中有没有特殊的字符转义方法

//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";

}
使用而不是
replaceText()


替换不是谷歌应用程序脚本中的一个函数?它是谷歌应用程序脚本项目中可用的javascript。刚刚在一个新的sheets脚本和独立脚本项目中再次测试了它。好吧,这意味着我需要首先将文本对象作为字符串进行正确设置?看起来它应该是
var text=DocumentApp.getActiveDocument().getBody().getText()
,然后是
.setText(text)
。我没有使用
DocumentApp()
方法,我想这是您正在检索的字符串。它对我仍然不起作用。对于replace(),它仍然不允许我用撇号替换单词,但常规单词确实有效。
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";
}