简体   繁体   中英

Check if string contains ANY string from the list in Visual Basic

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM