How to split text file by lines in one operator? [Q&A]
Using of dotnet constants
First of all, this is cheap solution which will do not work good for large files, but is completely OS independent.
StreamReader reader = File.OpenText(filename);
string file = reader.ReadToEnd();
reader.Close();
string[] elements = file.Split(Environment.NewLine.ToCharArray());
As I can see, I'm not first one who wrote such combination - http://www.google.com/search?hl=uk&rls=GGLG%2CGGLG%3A2005-30%2CGGLG%3Aen&q=Split+Environment+NewLine+ToCharArray
Applies to all dotnet languages: C#, VB.NET, C++.NET, J#

0 Comments:
Post a Comment
<< Home