Results 1 to 3 of 3

Thread: Search File for string containing list items

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2019
    Posts
    32

    Question Search File for string containing list items

    I have a list of graphic names, "graphicList". I need to search my file for each item in the graphicList in an entity string. I don't know how to reference each item in the graphicList and search for it.

    Code so far:

    Code:
     Dim Regex = New Regex("<!ENTITY .*?SYSTEM ""<graphicListItem>"" .*?>")
            Dim strMasterDoc = File.ReadAllText(FileLocation)
            Dim rxMatches = Regex.Matches(strMasterDoc)
            Dim entityList As New List(Of String)
    
            Dim entityFound As MatchCollection = Regex.Matches(strMasterDoc)
    
            'For each file's multipled image file references
            For Each m As Match In entityFound
                Dim found As Group = m.Groups(1)
                entityList.Add(found.Value)
            Next

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,561

    Re: Search File for string containing list items

    Code:
    dim list as new List(Of String)
    list.add("one")
    list.add("two")
    list.add("three")
    
    dim regString as String = "(" & String.Join("|", list.toarray) & ")"
    Then in your regex replace graphicListItem with regString

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,732

    Re: Search File for string containing list items

    Quote Originally Posted by .paul. View Post
    Code:
    dim list as new List(Of String)
    list.add("one")
    list.add("two")
    list.add("three")
    
    dim regString as String = "(" & String.Join("|", list.toarray) & ")"
    Then in your regex replace graphicListItem with regString
    Just one small note: String.Join has accepted any IEnumerable(Of T) for some time now, so the ToArray call is most likely not necessary. Does no real harm but does no real good either.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width