【问题标题】:Find a string in netsuite, and print it在 netsuite 中找到一个字符串,并打印它
【发布时间】:2016-12-05 13:40:35
【问题描述】:

在 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 中有类似的功能。

【问题讨论】:

    标签: netsuite suitescript


    【解决方案1】:

    使用RegExptest 方法。见MDN Reference

    看起来像

    var pattern = /world/;
    var n = pattern.test(str);
    

    String#includes 仅在 ES2015 中添加。 NetSuite 运行 Rhino 1.7 JS 引擎,不支持任何 ES2015 或更高版本的 JS 功能。

    【讨论】:

    • 您提供比 netsuite 金牌支持更好的解决方案。你提到的两件事都有效。谢谢
    • 我很好奇他们告诉你该怎么做。
    • 他们说:这不是 Netsuite 支持的一部分,因为您想要的解决方案与 javascript 有关。我告诉他们我只是给你一个我想要的例子,但他们告诉没有解决这个问题的方法。
    【解决方案2】:

    我通常选择搜索方法,它易于使用且易于阅读。如果找到单词,此方法返回第一次出现的索引,如果找不到单词,它将返回 -1。

    var hasWorld = str.search("world") !=-1;
    

    【讨论】:

      猜你喜欢
      • 2020-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-28
      • 1970-01-01
      • 1970-01-01
      • 2012-09-11
      相关资源
      最近更新 更多