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 Articles
- 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
- Web API + Unity - Reference object dbcontext already instantiated
- String.StartsWith not working with tilde ("~") characters LINQ to SQL?
- Linq Group By multiple fields and Flatten the list
- Remove <xyz> but gain data between
- LINQ - Sort List of objects using OrderBy EnumValue, and Union result set?
- C#: Sort DATATABLE with column date
- How does skip and take works in linq
- ASP.NET MVC & Entity - Loading Navigation Properiies/Objects When Using Raw SQL
- Why is Dictionary.Add overwriting all items in my dictionary?
- Entity Framework with LINQ, JOIN and ORDER BY with column in joined table
- EF Linq Select and Update or vise versa in one step
- How to bind data using custom form controller to view in mvc4
- InvalidOperationException: An exception was thrown while attempting to evaluate a LINQ query parameter expression
- Can 2d array be converted to usable list
- linq way to insert element in order
- DateTime Error When Saving Changes to DB
- C# Data Structure to allow fast finding of objects in a large dataset with a property between two given doubles
- See if Dictionary Item is the last one in the dictionary
- Shortcut LINQ toentity query for the following code in MVC 3
- LINQ with groupby and count