delphi - 在 TString 中搜索

标签 delphi delphi-xe2

如何检查 TStrings 中是否存在特定字符串?例如,我有包含大量文本的 TString,我想检查字符串是否为“Hello!”出现在本文中。

“你好!”只是一个示例字符串。它可以是任何东西。字符串可以位于其他字符串之间,例如“something Hello!something”

最佳答案

在 TStrings 文本属性上使用 pos 函数:

if pos('Hello!', strings.text) > 0 then
begin
end

如果字符串出现在 TString 中的任何位置,这将找到该字符串。要查找出现该情况的字符串,您需要遍历字符串,对每个字符串应用 pos 函数。

关于delphi - 在 TString 中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14015297/

相关文章:

delphi - 降序通用TObjectLIst

delphi - 恢复 TDBGrid 中的水平滚动位置

xml - MSXML 替代品

delphi - 使用 Firemonkey 和 Delphi XE2 进行数据库查找字段

delphi - 如何在 Delphi 中拥有一个在运行时和设计时工作的单例

delphi - 如何使用单独的 Label.Caption 更新来操纵某些 Control.OnMouseEnter 事件

windows - 如何使用 Delphi 获取与文件扩展名关联的程序名称?

delphi - 我如何制定创建表单的程序?

delphi - 关于TMemIni的教程

arrays - 两条记录共享相同的值?