2

how to check if a string "I want to eat apples", contains a string from the list of strings?

Here's the code that I'm trying to use:

Dim CONTAINER As String() = {"eat", "dog", "cat"}

    If STRING1.Text.Contains(CONTAINER(0..All?)) Then
        Dim ioFileT As New System.IO.StreamReader("C:\strings\RANDOMWORD.txt")
        Dim linesT As New List(Of String)
        Dim rndT As New Random()
        Dim lineT As Integer
        Dim RANDOMWORDFROMTXTFILE As String
        While ioFileT.Peek <> -1
            linesT.Add(ioFileT.ReadLine())
        End While
        lineT = rndT.Next(linesT.Count + 0)
        RANDOMWORDFROMTXTFILE = (lines(line).Trim())
        Console.Write(RANDOMWORDFROMTXTFILE)
    End If
1
  • Incidentally, you forgot to call ioFileT.Dispose() after using it. Or you might be interested in the File.ReadAllLines method, as in Dim linesT As String() = IO.File.ReadAllLines("C:\strings\RANDOMWORD.txt"). Commented Apr 26, 2020 at 15:18

1 Answer 1

4
If substringList.Any(Function(s) myString.Contains(s)) Then
    'myString contains at least one item from substringList.
End If
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.