簡體   English   中英

Google Apps 腳本 replaceText() 不能使用撇號“'”

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM