When reading some of the Wide Finder implementations, I come across with Don Box's approach. Besides the Wide Finder problem (be sure to look for this and other languages implementations), he gave us a nice clean generator based ReadLinesFromFile implementation. Here it is:
// LINQ-compatible streaming I/O helper
public static IEnumerable<string> ReadLinesFromFile(string filename){
using (StreamReader reader = new StreamReader(filename)){
while (true){
string s = reader.ReadLine();if (s == null)
break;
yield return s;
}}
}
3 comments:
(Your long lines have been chopped by this rubbish blogger software)!
Your right, my template choice was not the best to present code. I'll try to tweak this one, and if it doesn't work, change the template.
Thanks for your comment.
Here's the tweaking: http://devcatharsis.blogspot.com/2007/10/format-code-snippets-in-blogs.html
Post a Comment