reading a file from a specified place

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2007
Posts: 154
Reputation: mrjoli021 is an unknown quantity at this point 
Solved Threads: 0
mrjoli021 mrjoli021 is offline Offline
Junior Poster

reading a file from a specified place

 
0
  #1
Aug 11th, 2008
I have a txt file with three sections. i need to use section 1 for one function section 2 for a diffrent function and part 3 for the third function. how can i read the file from a specfied delimiter to another delimiter. so bascially i want to read what is inbetween both delimiters.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 58
Reputation: vckicks is an unknown quantity at this point 
Solved Threads: 9
vckicks vckicks is offline Offline
Junior Poster in Training

Re: reading a file from a specified place

 
0
  #2
Aug 11th, 2008
In this case I would load all the string data into a variable so you can use the StringReader class (in System.IO).

The StringReader object lets you read a text file line by line. So you could scan through the lines in search of your delimeters and only read the lines in between when you have found the appropriate start and stop reading when it finds the end.
Visual C# Kicks - Free C# code resources and articles.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 39
Reputation: nvmobius is an unknown quantity at this point 
Solved Threads: 4
nvmobius nvmobius is offline Offline
Light Poster

Re: reading a file from a specified place

 
0
  #3
Aug 11th, 2008
A standard piece of code I find myself using and reusing, time and time again...

  1. using ( FileStream fileStream = File.OpenRead(CONFIG_PATH) ) {
  2. Regex entryRegex = new Regex(@"^\s*(?<name>\S+?)\s*\:\s*(?<value>.+?)\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
  3.  
  4. using ( StreamReader reader = new StreamReader(fileStream) ) {
  5. while ( (line = reader.ReadLine()) != null ) {
  6. if ( entryRegex.IsMatch(line) ) {
  7. ...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC