尝试替换字符串的一部分时"Cannot find function replace"错误



我需要一种方法,使用Google Apps Script将字符串的一部分替换为另一个字符串。我测试了以下内容,它起作用了:

function test(){
  var value = 'https://plus.google.com/117520727894266469000';
  var googleimageURL = googlePlus(value);
  Logger.log('Returned Result: ' + googleimageURL);
}
function googlePlus(value){
    var apiKey = ScriptProperties.getProperty('apiKey');
    var re = 'http://'
    var theURL = value;
    Logger.log('Google+ is called: ' + value);
    var replacingItem = 'https://';
    var theURL = theURL.replace(re, replacingItem);
    Logger.log('Google+ Values 2: ' + value + ' : ' + theURL + ' after ' + replacingItem);
    return imageURL;
}

但是,当我嵌入到以下代码中时,它不起作用。知道吗?

  //If a Google+ column was not specified,put a flag.
  if (googleColumn && column == googleColumn) {
    if (value == ""){
      columns.push(nogoogleColumn);
      values.push(flag);
      var googleimageURL="";
    } else {
      var googleimageURL = googlePlus(value);
      Logger.log('Returned Result: ' + googleimageURL);
    }
  }

脚本没有按照我的意愿工作。它似乎停在行:

var theURL = theURL.replace(re, replacingItem);

附加信息:谷歌通知我以下消息

在表单上提交

类型错误: 在对象 https://plus.google.com/117520727894266469000 中找不到函数替换。(第 536 行)表单提交

我发现了错误。这是类型错误。 第二个块中的value不是"字符串",而第一个块是"字符串"。因此,要修复第二个块,我需要使用:

var value = value.toString();

在传递给googlePlus(value)之前

最新更新