从文本文件中的字节偏移确定行号 [英] Determine Line Number from Byte Offset in a text file
本文介绍了从文本文件中的字节偏移确定行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有一个场景,我知道文本文件的字节偏移量。我想知道无论如何我可以从字节偏移中确定行号。文本文件中的记录不是固定长度,在这种情况下,我会将偏移量除以宽度。
I currently have a scenario where I know the byte offset of a text file. I want to know is there anyway in which I can determine the line number from the byte offset. The records in the text file are not of fixed length, in which case I would have divided the offset by the width.
推荐答案
除非所有行都是统一长度,否则无法从字节偏移量确定行号。但是,您可以扫描换行并跟踪它们以计算文件中的偏移量。
You cannot determine the line number from byte offset unless all the lines are a uniform length. However you can scan for newlines and keep track of them to calculate the offset in the file.
这篇关于从文本文件中的字节偏移确定行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文