2017-10-03 13 views
1

「do not」を「do not」に置き換えようとすると、機能しませんが、通常の単語を使用すると、 します。私は "ドン\ t"でエスケープしようとしています。 Googleアプリスクリプトの文字をエスケープする特別な方法はありますか?Google AppsスクリプトreplaceText()がアポストロフィで動作しない ''」

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

} 

答えて

1

利用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"; 
} 
+0

交換するには、Google Appsのスクリプトでは関数ではありませんか? –

+0

Googleのスクリプトプロジェクトで利用できるjavascriptです。新しいシートスクリプトとスタンドアロンのスクリプトプロジェクトで再びテストしました。 –

+0

okこれは、文字列Objectを最初に正しいものにする必要があることを意味しますか? –

関連する問題