【发布时间】:2014-07-23 10:13:17
【问题描述】:
我有一个可以有以下子字符串值的字符串(也包括引号)
"+form"
"+ form "
" form+"
"form +"
+ form
+form
form+
form +
form +
+ form
....
....
.... or just simply 'form' that doesnt surrounded by double quotes
问题是找到与以下匹配的子字符串(+形式或形式+)
- '+ form' 不能用引号括起来
-
'+'和'form'之间的空格数不限
如果找到了,那么应该用空字符串“”代替
Input: ' form+ "form" + form ' Output: "form"输入: ' 形式' 输出: '形式'
有什么帮助吗?
我只是初学者,似乎无法通过简单的替换和方法索引来解决这个问题:-(
var abc = string.replace(" " + "");
if(abc.indexOf("+form") > -1 || abc.indexOf("form+") > -1 || abc.indexOf("form") > -1 || abc.indexOf("\"+form\"") > -1 || || abc.indexOf("\"form+\"") > -1 )
{
// then what should do?
}
【问题讨论】:
-
可以把你已经试过的JS代码加进去吗?
-
你从哪里得到这些输入? IE。真正的意图是什么?
-
我正在创建一个应用程序,用户输入例如(“字符串”+字符串)的代码,我需要单独解释。即字符串表示变量,“字符串”表示实际字符串
-
使用正则表达式可能是更好的选择..
标签: javascript string replace indexof