I am trying to read a text file but then only display the text that is between two line breaks.
So for example if I have this
<== Line Break ==> (1)
This is my text
<== Line Break ==> (2)
Some Text
Some Text
Some Text
Some Text
<== Line Break ==> (3)
Result
<== Line Break ==> (4)
Some other text not needing to show
So as you can see above I want to display the text between "Line Break" 1 and 4 only
What I have at the moment is this:
string file = "My Text File.txt";
string[] str = null;
if (File.Exists(Server.MapPath(file)))
{
str = File.ReadAllLines(Server.MapPath(file));
}
foreach (string s in str)
{
if (s.Contains("This is my text"))
{
btnText.Text = s.Replace(s, "Heading 1");
btnText.OnClientClick = ReadAdvertisingTest();
}
else if (s.Contains("This is my failed text"))
{
lblError.Text = lblError.Text + "n" + s.Replace(s, "Heading 2");
}
}
private string ReadAdvertisingTest()
{
<== This is where I need to display the text I want to have
}
The above code works great by finding the text then displaying in a Button
but I am not sure how to get the second part to work.
EDIT
So the output should then be:
This is my text
<== Line Break ==> (2)
Some Text
Some Text
Some Text
Some Text
<== Line Break ==> (3)
Result
So basically keep Line break 2 and 3 (if possible)
Any suggestions would help
Thanks
2
Answers
Ok, this is a bit ugly, but it will work:
So I read the text file, put it in a text box, and then 2nd text box shows the results:
In fact, this suggests quite much:
So, in place of that split() function, we could probably just concentate the result of the split and grab the 3 values in place of a "join", but above should suffice anyway.