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
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
Re: Search File for string containing list items
Quote:
Originally Posted by
.paul.
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.