admin管理员组文章数量:1389768
Is this ASP InStr function equivalent to the js indexOf function :
ASP :
<%
Function validation(ByVal var2)
If (InStr(var1, "," & var2 & ".") = 0) Then
validation = 1
Exit Function
End If
End Function
%>
JS :
validation = function(var2) {
if (var1.indexOf("," + var2 + ".") == -1) {
ValidateAction = 1;
};
return ValidateAction;
};
Is this ASP InStr function equivalent to the js indexOf function :
ASP :
<%
Function validation(ByVal var2)
If (InStr(var1, "," & var2 & ".") = 0) Then
validation = 1
Exit Function
End If
End Function
%>
JS :
validation = function(var2) {
if (var1.indexOf("," + var2 + ".") == -1) {
ValidateAction = 1;
};
return ValidateAction;
};
Share
Improve this question
asked Nov 1, 2019 at 12:35
user3470686user3470686
311 silver badge3 bronze badges
2
-
If you are only interested in checking if
var2
(with,
before and.
after) exists withinvar1
, then they are equivalent, yes. – Étienne Laneville Commented Nov 1, 2019 at 16:54 - OP problem solved ! – Bilal Siddiqui Commented Jul 25, 2020 at 6:13
1 Answer
Reset to default 4No, they are same only with one case. If value not found InStr return 0 and indexOf return -1, but Instr has many other, have a look on
Differences
The InStr function returns the position of the first occurrence of one string within another.
The InStr function can return the following values:
If string1 is "" - InStr returns 0
If string1 is Null - InStr returns Null
If string2 is "" - InStr returns start
If string2 is Null - InStr returns Null
If string2 is not found - InStr returns 0
If string2 is found within string1 - InStr returns the position at which match is found
If start > Len(string1) - InStr returns 0
Whereas javascript indexOf()
method returns the position of the first occurrence of a specified value in a string.
This method returns -1 if the value to search for never occurs.
本文标签: javascriptInStr vs indexOfStack Overflow
版权声明:本文标题:javascript - InStr vs indexOf - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744653506a2617826.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论