P
pmelanso
Hello,
I am trying to create a method that will see if one string contains a
different string:
This is what I have so far:
Private Function containString(ByVal string1 As String, ByVal
string2 As String) As Boolean
Dim firstString As String = string1
Dim stringToFind As String = string2
Dim stringToFindLength As Integer = string2.Length
Dim i As Integer
Dim endSubstringVal As Integer
If firstString.Length - stringToFindLength < 0 Then
Return False
Else
For i = 0 To firstString.Length - stringToFindLength
If firstString.Substring(i, i + stringToFindLength - 1)
= stringToFind Then
Return True
End If
Next
Return False
End If
End Function
But I keep getting this error:
Error Description:Index and length must refer to a location within the
string.
Parameter name: length
2: Source:mscorlib
2: Stack Trace: at System.String.Substring(Int32 startIndex, Int32
length)
Why is this???
Pam
I am trying to create a method that will see if one string contains a
different string:
This is what I have so far:
Private Function containString(ByVal string1 As String, ByVal
string2 As String) As Boolean
Dim firstString As String = string1
Dim stringToFind As String = string2
Dim stringToFindLength As Integer = string2.Length
Dim i As Integer
Dim endSubstringVal As Integer
If firstString.Length - stringToFindLength < 0 Then
Return False
Else
For i = 0 To firstString.Length - stringToFindLength
If firstString.Substring(i, i + stringToFindLength - 1)
= stringToFind Then
Return True
End If
Next
Return False
End If
End Function
But I keep getting this error:
Error Description:Index and length must refer to a location within the
string.
Parameter name: length
2: Source:mscorlib
2: Stack Trace: at System.String.Substring(Int32 startIndex, Int32
length)
Why is this???
Pam