34
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?

1

2 Answers 2

70

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

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, I am using like if Pos(content , container ) > 0 then showmessage('exists') else showmessage('Not exists'); But is there any other way
I don't understand your question, because so it would in Java
@delsql You are making something of a mess of this. Please don't ask new questions in comments to answers. If you want something different from containsIgnoreCase then, that would be a new question.
FWIR ContaintsText in Delphi 7 (mentioned by the topic starter ) only works for LATIN-1 characters set. If @delsql wants to compare some national characters (Greek, Russian, etc) he should use AnsiContainsText instead
For the ContainsText function, the needle is the 2nd parameter, not the first. For this example: if ContainsText('A.Sven,G.Jane,Jack', 'Jane') then
6

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 .... 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.