如何读取文本文件的特定行数不循环的ReadLine()? [英] How to read specific line number of text file without looping ReadLine()?

查看:190
本文介绍了如何读取文本文件的特定行数不循环的ReadLine()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一类,可以让你读取行号线在C#?

Is there a class that lets you read lines by line number in C#?

我知道的StreamReader和TextFieldParser但AFAIK那些不具备此功能。例如,如果我知道,行号34572在我的文本文件中包含的某些数据,这将是很好,不用调用 StreamReader.ReadLine() 34572次。

I know about StreamReader and TextFieldParser but AFAIK those don't have this functionality. For example, if I know that line number 34572 in my text file contains certain data, it would be nice to not have to call StreamReader.ReadLine() 34572 times.

推荐答案

除非文件具有precise和$ P $对确定的格式,例如与具有相同长度的每一行,也没有办法来争取在一个文本文件中。

Unless the file has a precise and pre-determined format, for instance with every line having the same length, there is no way to seek within a text file.

为了找到我行,你必须找到第i-1行结束。如果你不知道在哪里的线端可以是任何东西,它遵循,你必须阅读整个文件,直到我行。

In order to find the ith line, you must find the first i-1 line ends. And if you do not know anything about where those line ends could be, it follows that you must read the entire file up until the ith line.

这篇关于如何读取文本文件的特定行数不循环的ReadLine()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆