943,918 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 1062
  • C# RSS
Aug 11th, 2008
0

reading a file from a specified place

Expand Post »
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.
Similar Threads
Reputation Points: 7
Solved Threads: 0
Junior Poster
mrjoli021 is offline Offline
170 posts
since Mar 2007
Aug 11th, 2008
0

Re: reading a file from a specified place

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.
Reputation Points: 11
Solved Threads: 9
Junior Poster in Training
vckicks is offline Offline
58 posts
since Jun 2008
Aug 11th, 2008
0

Re: reading a file from a specified place

A standard piece of code I find myself using and reusing, time and time again...

C# Syntax (Toggle Plain Text)
  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. ...
Reputation Points: 11
Solved Threads: 4
Light Poster
nvmobius is offline Offline
39 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: C# and VBA problem....
Next Thread in C# Forum Timeline: Windows application on a server





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC