Google apps script 电子表格-谷歌脚本-如何使用“查找字符串中的文本”;findText();方法?

Google apps script 电子表格-谷歌脚本-如何使用“查找字符串中的文本”;findText();方法?,google-apps-script,Google Apps Script,这是我的GS的碎片。当我运行时,它返回错误“TypeError:text.findText不是函数”。 我犯了什么错误?谢谢 var text = "Martin test x"; Logger.log(text); var range2 = text.findText("x"); 我希望结果中的范围值为“12”。实际上是12 function myfunction() { var text = "Martin test x"; Logger.log(text.indexOf('x'

这是我的GS的碎片。当我运行时,它返回错误“TypeError:text.findText不是函数”。 我犯了什么错误?谢谢

var text = "Martin test x";
Logger.log(text);
var range2 = text.findText("x");
我希望结果中的范围值为“12”。

实际上是12

function myfunction() {
  var text = "Martin test x";
   Logger.log(text.indexOf('x'));
}

你可以使用indexOf()谢谢你,库珀,它很有用,而且工作得很好。总之,“findText()”有什么问题吗?它不能用于搜索字符串中的位置?它不是Javascript中的字符串方法,而是document.getBody().findText()方法。