score:14
Accepted answer
File.ReadAllLines(myFile)
.Select(l => l.Split(' ').Select(int.Parse).ToArray()).ToArray();
Or:
List<int[]> forThoseWhoHave1GigFiles = new List<int[]>();
using(StreamReader reader = File.OpenText(myFile))
{
while(!reader.EndOfStream)
{
string line = reader.ReadLine();
forThoseWhoHave1GigFiles.Add(line.Split(' ')
.Select(int.Parse).ToArray());
}
}
var myArray = forThoseWhoHave1GigFiles.ToArray();
And:
File.ReadLines(myFile)
.Select(l => l.Split(' ')
.Select(int.Parse).ToArray())
.ToArray();
In .Net 4.0 and above.
score:2
Do you mean something like this?
StreamReader sr = new StreamReader("./files/someFile.txt");
var t1 =
from line in sr.Lines()
let items = line.Split(' ')
where ! line.StartsWith("#")
select String.Format("{0}{1}{2}",
items[1],
items[2],
items[3]);
Take a look to this web: LINK
score:5
Just to complete Jonathan's answer, here's how you could implement the Lines
extension method :
public static class TextReaderExtensions
{
public static IEnumerable<string> Lines(this TextReader reader)
{
string line;
while((line = reader.ReadLine()) != null) yield return line;
}
}
Source: stackoverflow.com
Related Query
- Read text data from file using LINQ
- How to read data from xml file using linq to xml?
- How to read File names recursively from subfolder using LINQ
- Read first 10 line from file using LINQ
- reversing text from input file using linq
- Read text file word-by-word using LINQ
- Read from xml file to objectlist using Linq
- read icollection data using LINQ in C# code
- Take unique records from text file using LINQ
- Linq - using not "IN" operator to select non duplicated lines from a text file
- How to sort data loaded from a file using LINQ
- Read Child nodes including text and node using XPath from XElement ? LinQ
- How to display data from XML file to ListView using LINQ to XML?
- How to read data with pagination from large xml file using c#
- How to reinsert data from one table onto itself using LINQ in code migration?
- Using LINQ to read key value pair from configuration file
- Construct a list of wpf Hyperlink elements from an XML source file using Linq
- Using LINQ to get a string from a tab delimited text file into an array in the way I want
- How to add data to a dictonary from xml file in c# using XML to LINQ
- How do I get SOAP xml file data using LINQ and display it in a form's text box? C#
- c# Linq or code to extract groups from a single list of source data
- how to fetch data from database using linq query for relationship 1:N and N:N (between 3 entity) in asp.net mvc EF code first?
- How to output data on to a CSV file, after extracting data from XML file using LINQ C#?
- How to read a CSV file using linq after the csv file is downloaded from Azure?
- Read a text file using LinQ and then insert it into SQL Table using LinQ To SQL
- add data to existing xml file using linq
- read xml file using linq
- Retrieving Data from database within the last 7 days using linq
- Extract data from a XML string using linq vs xmlDocument
- How to read XML file using System.IO.Stream with LINQ
More Query from same tag
- Condition doesn't return true when it should
- Is there a solution that will convert the following LINQ Query Syntax to Method Syntax with Lambdas
- LINQ Concat nested queries sorting
- Custom Linq query Help Needed
- Using LinQ with group by more than one column
- Easy way to flatten XML file with LINQ
- Linq statement for an infinite sequence of successive halves
- Using ternary operator to check if null - null reference is not the same as null
- Linq Contains method for a object
- How To Use Yield Inside A Linq Query
- Linq selecting range of records
- ASP.NET - Advanced Where-Clause in LinqDataSource
- Using Linq to replace foreach statement
- Enumerating return list from simple.data
- How to append strings in an array using C# or LINQ
- EF Select records distinct by one field from Entity
- Converting an SQL query in to LINQ C#
- Merging two Lists and a dictionary to create a single dictionary
- XPath / linq to xml: xmlns=""testNS"" results in no result
- Optional requirement on where clause in LINQ
- LINQ Filtering - Optimization
- LINQ - check for equality inside join
- Rails 3: sql injection free queries
- LINQ query to get the all the datarows based on a distinct column
- After grouping by, can I refer to the elements of the original IEnumerable in a LINQ query?
- Compare efficiency of two different LINQ statements
- Linq return unique records with count of duplicates
- How can i use LINQ to pass highlighted Cells to another DataGridView?
- Why is the method not getting called?
- Function and LINQ query not working as needed