C# 从特定位置读取文本文件到 EOF
尝试找到一种好方法来读取文本文件并找到某个短语的最后一个实例,然后从该点读取文件到末尾。
简化的示例
sometext1...
sometext2...
[new]
sometext3...
[new]
sometext4...
sometext5...
[new]
sometext6...
sometext7...
“我想要返回”是写的最后一部分,
[new]
sometext6...
sometext7...
我可以想出方法来做到这一点,但我确信有一种非常有效的方法。 猜测必须找到“[new]”的最后一个索引并从那里读取。
Trying to find a good way to read a text file and find the last instance of a certain phrase and read the file to the end from that point.
example simplified
sometext1...
sometext2...
[new]
sometext3...
[new]
sometext4...
sometext5...
[new]
sometext6...
sometext7...
Want i want returned is the last part written
[new]
sometext6...
sometext7...
I can think of ways to do this, but i'm sure there is a very efficient way.
Guessing would have to find the last index of "[new]" and read from there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设:
然后我会做以下事情。改变前三个假设,事情会变得更棘手,改变第四个假设,我会很懒,只需将整个内容加载到:
Assuming:
Then I would do the following. Change the first three assumptions and it gets trickier, change the fourth and I'd be lazy and just load the whole thing in:
您可以打开一个文件流,将其包装到 TextReader 中,然后将 Position 属性的值保存在 FileStream 实例中。它允许您保存[新]代币的位置。
You can open a file stream, wrap it into TextReader, then save value of Position property in FileStream instance. It allows you to save positions of [new] tokens.