在netsuite中找到一个字符串,打印出来
Find a string in netsuite, and print it
在netsuite suitescript 1.0中,我想检查一个字符串是否有一组关键字。在 javascript 中有一个名为 .includes("Set_of_keywords_to_be_searched") 的函数;
我在 netsuite 中尝试了 .includes 但它给出了错误。
例如:
var str = "Hello world, welcome to the javascript.";
var n = str.includes("world"); // this will return true
var n = str.includes("Apple"); // this will return false
我想要netsuite中的类似功能。
使用 RegExp
和 test
方法。参见 MDN Reference
看起来像
var pattern = /world/;
var n = pattern.test(str);
String#includes
仅在 ES2015 中添加。 NetSuite 是运行 Rhino 1.7 JS 引擎,不支持任何ES2015 或更高版本的JS 功能。
我通常使用搜索方法,它易于使用且可读性强。如果找到单词,此方法 returns 第一次出现的索引,如果找不到单词,它将 return -1。
var hasWorld = str.search("world") !=-1;
在netsuite suitescript 1.0中,我想检查一个字符串是否有一组关键字。在 javascript 中有一个名为 .includes("Set_of_keywords_to_be_searched") 的函数; 我在 netsuite 中尝试了 .includes 但它给出了错误。
例如:
var str = "Hello world, welcome to the javascript.";
var n = str.includes("world"); // this will return true
var n = str.includes("Apple"); // this will return false
我想要netsuite中的类似功能。
使用 RegExp
和 test
方法。参见 MDN Reference
看起来像
var pattern = /world/;
var n = pattern.test(str);
String#includes
仅在 ES2015 中添加。 NetSuite 是运行 Rhino 1.7 JS 引擎,不支持任何ES2015 或更高版本的JS 功能。
我通常使用搜索方法,它易于使用且可读性强。如果找到单词,此方法 returns 第一次出现的索引,如果找不到单词,它将 return -1。
var hasWorld = str.search("world") !=-1;