如何用iMacros下的条件替换字符串的特定部分
How to replace only specific part of the string with condition under iMacros
我想做以下帮助我制作这个脚本:
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 (web自动化软件)下工作
SOLVED: SET !VAR2 EVAL("'{{!EXTRACT}}'.includes('ABC') ? '{{!EXTRACT}}'.replace('ABC','') : '{{!EXTRACT}} ABC';")
try this:
var str = "Whatever words ABC";
if (str.indexOf('ABC') !== -1)
str.replace('ABC', '')
else
str+= ' ABC'
试试这个
var str ="ABCDEFGHI"
if(str.indexOf("ABC") !== -1){
str.replace(/ABC/g,"")
}else{
str=str+"ABC"
}
使用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);
相关文章:
- 将敲除绑定应用于模板,并将结果作为字符串获取
- 我们可以将ng绑定值存储到php字符串中吗
- 挖空 HTML 绑定和字符串格式的 HTML 长度
- 是否可以使用Angular2将自定义字符串轻松绑定到html元素中的id和for
- Popover未将字符串绑定为html angularjs
- angular js$scope变量与字符串绑定
- angular2中具有属性绑定的字符串串联
- 挖空 JS html 绑定返回奇怪的代码而不是 html 字符串
- 从 jQuery 中的字符串中获取部分值
- 从链接内的数据绑定中获取字符串
- 使用字符串键绑定嵌套对象
- 如何在绑定到使用 ngBindHTML 查看时缩短 HTML 字符串的内容文本
- 如何在 angularjs 中绑定为字符串的 html 部分
- AngularJS - 需要帮助在绑定文本输入中显示字符串的当前长度
- 如何在 javascript src 字符串中插入 ASP.NET 数据绑定器
- 剑道绑定属性与字符串和变量
- 双向绑定 ng-repeat 中的字符串数组
- SAPUI5/OPENUI5:将字符串绑定到 JSON 模型并自动更新更大的字符串(读取 [对象%20Object])
- 如何使用 AngularJS 绑定后获取元素的字符串长度
- 敲除.js如何从绑定构建字符串