VBScript Instr函数始终返回0

VBScript Instr function always return 0

我有一个由经典ASP编写的应用程序。 我需要比较string1是否包含string2,所以我使用instr函数。 但是,即使string1包含string2,它也始终返回0。我的代码在哪里出现问题?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function Findstring(string1,string2)
    dim findstr,loc

    on error resume next
    loc= instr(1,Lcase(string1),Lcase(string2),1)
    if loc>0  then
        findstr=true

    else
        findstr= false

    end if


  end function


1
2
3
4
5
Function FindString( string1, string2 )
    FindString = False
    On Error Resume Next
    FindString = CBool( InStr(1, LCase(string1), LCase(string2), 1) > 0 )
End Function

如果string1False内包含string2,则此函数将返回True

注意:如果比较运算符>已经生成布尔值,为什么CBool? 因为我们可以调用传递Null值的函数。 如果要比较的任何字符串是Null,则InStr函数将返回Null,并且测试Null > 0的计算结果为Null。 但是CBool( Null )会生成一个错误,该错误由先前的On Error捕获(它还将处理对象问题)