Asp classic 在asp classic中:如何确保变量可以转换为int?

Asp classic 在asp classic中:如何确保变量可以转换为int?,asp-classic,casting,Asp Classic,Casting,向我建议了以下功能: ' Defines a forced casting function, which "casts" anything that it can't detect as a number to zero. Function MakeInteger(val) If IsNumeric(val) Then MakeInteger = CInt(val) Else MakeInteger = 0 End I

向我建议了以下功能:

' Defines a forced casting function, which "casts" anything that it can't detect as a number to zero.
    Function MakeInteger(val)
      If IsNumeric(val) Then
        MakeInteger = CInt(val)
      Else
        MakeInteger = 0
      End If
    End Function
不幸的是,对于IsNumeric,似乎有一些东西返回true,但仍然无法转换为int。是否有更好的检查方法可供使用?

请参阅。他们给出了这个解决方案:

<% 
    function isReallyNumeric(str) 
        isReallyNumeric = true 
        for i = 1 to len(str) 
            d = mid(str, i, 1) 
            if asc(d) < 48 OR asc(d) > 57 then 
                isReallyNumeric = false 
                exit for 
            end if 
        next 
    end function 

    response.write isReallyNumeric("3e4") & "<p>" 
    response.write isReallyNumeric("3d4") & "<p>" 
    response.write isReallyNumeric("&H05") & "<p>" 
    response.write isReallyNumeric("$45,327.06") & "<p>" 
    ' and a sanity check: 
    response.write isReallyNumeric("1234") & "<p>" 
%>
如果你想的话,你必须调整 接受某些字符作为 “数字”,例如逗号、十进制 点、+和-符号等

看看这个。他们给出了这个解决方案:

<% 
    function isReallyNumeric(str) 
        isReallyNumeric = true 
        for i = 1 to len(str) 
            d = mid(str, i, 1) 
            if asc(d) < 48 OR asc(d) > 57 then 
                isReallyNumeric = false 
                exit for 
            end if 
        next 
    end function 

    response.write isReallyNumeric("3e4") & "<p>" 
    response.write isReallyNumeric("3d4") & "<p>" 
    response.write isReallyNumeric("&H05") & "<p>" 
    response.write isReallyNumeric("$45,327.06") & "<p>" 
    ' and a sanity check: 
    response.write isReallyNumeric("1234") & "<p>" 
%>
如果你想的话,你必须调整 接受某些字符作为 “数字”,例如逗号、十进制 点、+和-符号等