繁体   English   中英

Delphi中如何判断一个字符串是否包含子字符串?

[英]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

我是德尔福的新手。 Delphi中是否有contains命令或执行相同操作的任何其他命令?

您可以在Delphi中使用StrUtils中的函数

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

如果在给定文本中找到不区分大小写的子文本,则ContainsText返回true

StrUtils ,您还会发现StartsTextEndsTextReplaceText等方便的函数

您可能还会发现System.SysUtils中的Contains函数有帮助,如下所示。

uses
  Sysytem.SysUtils;

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

  if txt.contains('str') then
....

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM