Extracting from Text Files

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a small text file of data and I would like to be able to search for a
string and on finding that string extract the data that follows it. Is there
an easy way to do this? I have been using StreamReader to read the file but I
am unsure as to how to actually test the string and then extract the
following data I require.

thanks
 
Hi Liz
You can need to load or you file first into a string then you can use the
index of function to search for any assurance of your string ( the one you
are searching for ) into the file ( that is now loaded in the big string)
Int k = BigString.IndexOf( small string) .
If this gives you positive number then this is where you find you're your
string if -1 then the string you are looking for doesn't exist in the file.
Hope this helps
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC
 
Hi,

In addition to previous answer...
I think that is the best solution for a very small
files (e.g. tens of kBytes):
string wholeTextOfFile=streamReader.ReadToEnd();

If you're sure that searched string doesn't
contain a new line characters the i can recoment to
read it line by line, and search each line with
method "IndexOf". In a case of "first occurence",
this should be the best (fastest) solution i think.

Cheers!
Marcin
 
Back
Top