coo*_*mer 8 c# position stream streamreader
我只想阅读一个大型CSV文件并将Stream位置保存在列表中.之后我必须从列表中读取位置并将Streamreader的位置设置为该char并读取一行!但在我读完第一行并返回streamposition后
StreamReader r = new StreamReader("test.csv");
r.readLine();
Console.WriteLine(r.BaseStream.Position);
Run Code Online (Sandbox Code Playgroud)
我得到"177",这是文件中的总字符数!(这只是一个简短的示例文件)我没有在这里发现任何类似的东西,它帮助了我!
为什么?
完全方法:
private void readfile(object filename2)
{
string filename = (string)filename2;
StreamReader r = new StreamReader(filename);
string _top = r.ReadLine();
top = new Eintrag(_top.Split(';')[0], _top.Split(';')[1], _top.Split(';')[2]);
int siteindex = 0, index = 0;
string line;
sitepos.Add(r.BaseStream.Position); //sitepos is the a List<int>
while(true)
{
line = r.ReadLine();
index++;
if(!string.IsNullOrEmpty(line))
{
if (index > seitenlaenge)
{
siteindex++;
index = 1;
sitepos.Add(r.BaseStream.Position);
Console.WriteLine(line);
Console.WriteLine(r.BaseStream.Position.ToString());
}
}
else break;
maxsites = siteindex;
}
reading = false;
}
Run Code Online (Sandbox Code Playgroud)
该文件如下所示:
name;age;city
Simon;20;Stuttgart
Daniel;34;Ostfildern
Run Code Online (Sandbox Code Playgroud)
等等,这是一个程序练习: http ://clean-code-advisors.com/ressourcen/application-katas(Katas CSV viewer)我目前正在阅读3
| 归档时间: |
|
| 查看次数: |
26303 次 |
| 最近记录: |