Checking for existence of 2 or more strings in an expression

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,

Is there a function in vb.net to scan through an expression and check
whether it contains any string from a list of strings provided?

Thanks.
 
SM,

AFAIK does that not exist for strings, it exist for an array of characters.

For Strings you have to build that yourself. (Not that much work in my
opinion)

Cor
 
Thanks

Cor Ligthert said:
SM,

AFAIK does that not exist for strings, it exist for an array of characters.

For Strings you have to build that yourself. (Not that much work in my
opinion)

Cor
 
SM,

Because I have said somewhere in the discussion which Jay showed that I
would once make that routine I did it today. I did not test how efficient it
is and I took the most simple format.

\\\Test module
Public Module main
Public Sub main()
Dim Text As String = "This is a test to see if a word exist"
Dim StringArray() As String = {"see", "test", "microsoft"}
Dim i As Integer = FindArrayString.FindStringOfAny(Text,
StringArray)
End Sub
End Module
///
\\\Class
Public Class FindArrayString
Public Shared Function FindStringOfAny(ByVal Text As String, _
ByVal StringArray As String()) As Integer
For i As Integer = 0 To Text.Length - 1
For y As Integer = 0 To StringArray.Length - 1
Dim length As Integer = StringArray(y).Length
If i + length < Text.Length Then
If Text.Substring(i, length) = StringArray(y) Then
Return i
End If
End If
Next
Next
Return -1
End Function
End Class
///

Maybe somebody else will test that.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top