The text in my application’s log file is separated by —- dotted lines.
How can I read each paragraph as a string ? For example : Audit paragraph as string[0], Transaction paragraph as string 1 and so on ….till the end paragraph where there is no dotted line at last.
>Solution :
There you go:
IEnumerable<string> ReadParagraphs(IEnumerable<string> source)
{
var output = new List<string>();
foreach (var line in source)
{
if (line != "-------") // you count your `'`
{
if (output.Count > 0)
{
yield return String.Join(Environment.NewLine, output);
output.Clear();
}
}
else
{
output.Add(line);
}
}
if (output.Count > 0)
{
yield return String.Join(Environment.NewLine, output);
}
}
