var t1 = from line in File.ReadAllLines(@"alkahf.txt")
let item = line.Split(new string[] {". "}, StringSplitOptions.RemoveEmptyEntries)
let verse = line.Split(new string[] { "\n. " }, StringSplitOptions.RemoveEmptyEntries)
select new
{
Index = item,
Text = verse
};
having problems with above code im unsure how to parse the lines properly.
the format of the file is like so, I would also like to ignore any empty lines
StringSplitOptions.RemoveEmptyEntries doesn’t work for some reason
1. This is text it might have numbers
2. I skipped a line
In the LINQ part, you are inside a single line, so you might want to exclude the empty lines first:
You then do two splits – one on newline, which is odd (since that won’t be there, since we know we are reading lines). I expect you mean something like:
?
Also, note that
ReadAllLinesis a buffered operation; if you want true streaming, you might want something like:which is not buffering (you don’t load the entire file at once). Just change the first line to: