Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq and streamreader getting lines

Tags:

c#

linq

Using LINQ, what is an efficent way to get each string from a tab-delimited .txt file (and then get each word, usually what string.Split(...) does)?

var v = from line in File.ReadAllLines()
   select n

Is part of this solution I believe. I don't mind if this uses yield return.

EDIT: I've also seen threads on here detailing exactly what I am trying to do, but can't find them.

like image 258
GurdeepS Avatar asked Feb 23 '10 17:02

GurdeepS


1 Answers

I'm not entirely sure what you're asking but it sounds like you're trying to get every word from a tab delimited file as an IEnumerable<string>. If so then try the following

var query = File.ReadAllLines(somePathVariable)
                .SelectMany(x => x.Split(new char[] { '\t' });
like image 128
JaredPar Avatar answered Oct 19 '22 09:10

JaredPar