How can I check if a particular string exists in a TStrings ? For example I have TStrings which contain a lot of text and I want to check if string "Hello!" is present in this text.
"Hello!" is just an example string. It can be anything. String can be in between other strings like "something Hello! something"
Use the pos function on the TStrings text property:
if pos('Hello!', strings.text) > 0 then
begin
end
This will find the string if it occurs anywhere in the TStrings. To find the string in which it occurs you would need to iterate through the strings applying the pos function on each of them.
You can use the IndexOf function of TStrings
if Strings.IndexOf('Hello')<>-1 then
caption:='Found';
This function return -1 if the string was not found, else it returns the index of this string in the TStrings;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With