功能溢出错误

时间:2013-11-01 10:50:49

标签: vb.net function overflow runtime-error

Public Function checkForChars(ByVal arrayOfChars As String(), ByVal stringToCheck As String) As Boolean
        Dim i As Integer
        Dim numEntries As Integer = arrayOfChars.Length - 1
        For i = 0 To numEntries
            If (stringToCheck.Contains(arrayOfChars(numEntries)) = True) Then
                Return True
            End If
        Next

        Return False

End Function

嘿,我正在使用上面的函数来检查字符串中的字符数组,但是如果字符串太长则会产生算术溢出错误(表明我已经除以0)。目前我实际上正在使用一个整数value.toString,有人可以对此有所了解吗?

由于

1 个答案:

答案 0 :(得分:1)

您的代码存在一些问题,我对其进行了一些修改。检查它是否适合你

Public Function checkForChars(arrayOfChars As String(), stringToCheck As String) As Boolean
    For i As Integer = 0 To arrayOfChars.Length - 1
        If stringToCheck.Contains(arrayOfChars(i)) Then
            Return True
        End If
    Next

    Return False
End Function