RegEx - Is this doable? In .NET

  • Thread starter Thread starter VC
  • Start date Start date
V

VC

Hi All,
Here is what I am trying to do.
I have a list of strings (Array, Collection or some store) stringlist1
I have an input text file. datafile1.txt
Given the list of strings and this input file, I want to parse the file and
see if the strings are found in the file. The result from this operation is
a list that contains only those strings from "stringlist1" that had a match
in the input file.

Is it a straighforward call or should I iterate through the file line by
line and then do a match/comparison for all items in the stringlist?

Thanks for your time,
V!
 
VC said:
I have a list of strings (Array, Collection or some store) stringlist1
I have an input text file. datafile1.txt
Given the list of strings and this input file, I want to parse the file and
see if the strings are found in the file. The result from this operation is
a list that contains only those strings from "stringlist1" that had a match
in the input file.

Is it a straighforward call or should I iterate through the file line by
line and then do a match/comparison for all items in the stringlist?

There's no call that will do that for you, so you're right, you'll have to
iterate over the lines in the file. I guess you'll be better off (because
it's faster) using the String.IndexOf method instead of regular
expressions as long as your match list really contains regular strings only.


Oliver Sturm
 
Thanks a lot oliver. I am doing exactly what you recommended.
Thanks for your time, Have a great day!!!
V!
 
There's no call that will do that for you, so you're right, you'll have to

Actually, I would read the whole file into a single string, then iterate
through the list of items and search using String.IndexOf. Much faster than
a line-by-line access of the file unless you have some need to know what line
something's on.
 
Chuck said:
Actually, I would read the whole file into a single string, then iterate
through the list of items and search using String.IndexOf. Much faster
than
a line-by-line access of the file unless you have some need to know what
line
something's on.

Or unless your file is just a too large for that. Line by line reading is
extremely easy to code and much more efficient memory-wise, so I would
usually opt for that - why do you believe that reading the whole file into
a string should be significantly faster?


Oliver Sturm
 
Back
Top