0

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.

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by nvmobius
0

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.

0

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

using ( FileStream fileStream = File.OpenRead(CONFIG_PATH) ) {
                Regex entryRegex = new Regex(@"^\s*(?<name>\S+?)\s*\:\s*(?<value>.+?)\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase);

                using ( StreamReader reader = new StreamReader(fileStream) ) {
                    while ( (line = reader.ReadLine()) != null ) {
                        if ( entryRegex.IsMatch(line) ) {
...
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.