Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a string contains a substring in Delphi?

String content = "Jane";
String container = 'A.Sven,G.Jane,Jack'; // This is the string which i need to be searched with string content

boolean containerContainsContent = StringUtils.containsIgnoreCase(container, content); // I used to write like this in java

I am new to Delphi. Is there a contains command in Delphi or any other command which performs the same operation?

like image 365
delsql Avatar asked Oct 29 '15 09:10

delsql


2 Answers

You can use the functions in StrUtils in Delphi

uses   StrUtils; ..     if ContainsText('A.Sven,G.Jane,Jack', 'Jane') then      ... 

ContainsText returns true if the subtext is found, without case-sensitivity, in the given text

In StrUtils you'll also find handy functions like StartsText, EndsText and ReplaceText

like image 144
Jens Borrisholt Avatar answered Sep 20 '22 13:09

Jens Borrisholt


You might also find helpful the Contains Function in System.SysUtils as below.

uses
  Sysytem.SysUtils;

....
  txt := 'This is a string variable';

  if txt.contains('str') then
....
like image 25
codeGood Avatar answered Sep 21 '22 13:09

codeGood