Delphi - 在大型 TMemo 中查找文本
我有一个TMemo,其中包含相当多的文本,80M(大约400K行)。
TMemo 设置为 WordWrap = FALSE,不需要查找换行为 2 行的文本。
我需要一种快速的方法来从头开始查找文本,并查找下一个文本。
因此,我放置了一个 TEdit 来放置要查找的文本,并放置了一个 TButton 来在 TMemo 中查找文本。
我想使用 Pos() 逐行检查,但这会很慢。 我不知道如何确定当前光标位置的 TMemo.Lines[index] 。
任何人都可以想出解决方案吗?
谢谢
更新:
我从这里找到了解决方案: 在 Delphi 中搜索备忘录?
SearchText() 函数工作速度快,而且速度非常快。 花了几秒钟来搜索底部的唯一字符串。
I have a TMemo which contains quite a lot of texts, 80M (about 400K lines).
The TMemo is set with WordWrap = FALSE, there is no need to find texts that wrapped in 2 lines.
I need a fast way to find a text, from the beginning, and also find next.
So, I put a TEdit for putting the text to find and a TButton to find the text in the TMemo.
I was thinking to use Pos(), checking line by line, but that will be slow.
And I don't know how to determine the TMemo.Lines[index] for current cursor position.
Anyone can come up with solution?
Thanks
UPDATE:
I found a solution from here:
Search thru a memo in Delphi?
The SearchText() function works, fast, and very fast.
Took couple of seconds to search unique string at the bottom end.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对之前的答案的一点补充:您无需选择即可获取行号找到的模式,如下所示:
请注意,行号是从零开始的,您还应该从
Pos
结果中减去 1 以获得SendMessage
的从零开始的偏移量,并且TMemo.SelStart
。A little addition to the previous answers: you can get the line number without selecting the pattern found, like this:
Note that line number is zero-based, also you should subtract 1 from
Pos
result to obtain zero-based offset forSendMessage
andTMemo.SelStart
.