【问题标题】:How to replace only specific part of the string with condition under iMacros如何在 iMacros 下仅用条件替换字符串的特定部分
【发布时间】:2016-09-08 10:44:37
【问题描述】:

我想做以下帮助我制作这个脚本:

if form text include = "ABC" (for example: "Whatever words ABC")
then delete the word "ABC" (so it become "Whatever words")

AND

if form text doesn't include = "ABC"
then add the word at the end "ABC (so it become "Whatever words ABC")

请注意:我不想只触摸包含的字符串"ABC" 的部分,或者只删除这部分。

希望你能理解。

我需要这个脚本在 iMacros(网络自动化软件)下工作

已解决: SET !VAR2 EVAL("'{{!EXTRACT}}'.includes('ABC') ? '{{!EXTRACT}}'.replace('ABC','') : '{{!EXTRACT}} ABC';")

【问题讨论】:

  • 伙计们,我真的很抱歉我需要这个脚本在 iMacros(一个网络自动化软件)中工作我希望你知道,它使用 javascript 结合它自己的脚本我不知道是什么他们称之为但它有点不同。请告诉我如何使这个脚本在那个非常有用的程序下工作。
  • 已解决:经过一些深入的搜索和跟踪和错误,我想通了: SET !VAR2 EVAL("'{{!EXTRACT}}'.includes('ABC') ? '{{!EXTRACT }}'.replace('ABC','') : '{{!EXTRACT}} ABC';")

标签: javascript automation imacros


【解决方案1】:

试试这个:

    var str = "Whatever words ABC";

    if (str.indexOf('ABC') !== -1)
      str.replace('ABC', '')
    else
      str+= ' ABC'

【讨论】:

  • 谢谢你,但你知道如何让这个脚本在 iMacros 软件中工作吗?
【解决方案2】:

试试这个

var str ="ABCDEFGHI"


if(str.indexOf("ABC") !== -1){
str.replace(/ABC/g,"")
}else{
str=str+"ABC"
}

【讨论】:

    【解决方案3】:

    使用replace() 删除特定文本,使用concat() 添加文本。

    var str = "Whatever words ABC";
    var newStr = "";
    
    if (str.indexOf("ABC") > -1) {
      newStr = str.replace(" ABC", "");
    } else {
      newStr = str.concat(" ABC");
    }
    
    console.log(newStr);

    【讨论】:

      猜你喜欢
      • 2020-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-20
      • 2021-10-10
      • 2011-05-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多