i have text file and read it using stream reader, when my file is having empty line along with data, it does not read any thing. how to remove the empty line using C#.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
You haven't shown any code, and your description is pretty woolly, but as of .NET 4 this would be a very easy way to do what you want:
Note that it won't perform any trimming, so a line with only spaces in would still be returned.
Also note that the code above doesn't read the file when you just execute that line - it will only read it when you try to iterate over
lines
, and will read it again every time you iterate overlines
. If you want to read it into memory all in one go, you might want:Below is the code:
Well, you should use the method "ReadLine()" from the StreamReader in a loop. When you receive an empty line, simply check if the string obtained from ReadLine() is empty. If it is, ignore the line. Try something like: