如何检查 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/