0
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

Hey, I'm using the above function to check a string for an array of characters, but if the string is too long it gives an arithmetic overflow error (suggesting that I've divided by 0). At the moment I'm actually using an integer value.toString, can someone shed some light on this?

Thanks

3
  • The length of the array is greater than the max. Integer value? This sounds too big and indicates that you should face the problem in a different way. Can you please explain where is a so big array coming from? Commented Nov 1, 2013 at 10:55
  • Can you tell us the exact error message and in which line you get the exception? Your code above is a bit weird. You check always the last string, then why do you loop over the entries? Commented Nov 1, 2013 at 10:59
  • Oops sorry, I modified a variable name and forgot to modify the rest of the code. Vlad's answer seems to have worked, thanks for you time guys... Always get the weirdest errors I do... Commented Nov 1, 2013 at 16:19

1 Answer 1

1

Your code has some issues, I've modified it a little. Check if it works for you

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.