【问题标题】:How to check if a string contains a substring in Delphi?Delphi中如何判断一个字符串是否包含子字符串?
【发布时间】:2015-10-29 09:18:41
【问题描述】:
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 的新手。 Delphi 中是否有contains 命令或执行相同操作的任何其他命令?

【问题讨论】:

标签: delphi delphi-7


【解决方案1】:

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

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

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

StrUtils 中,您还可以找到方便的函数,例如StartsTextEndsTextReplaceText

【讨论】:

  • 谢谢,我使用 like if Pos(content , container) > 0 then showmessage('exists') else showmessage('Not exists');但是有没有其他办法
  • 我不明白你的问题,因为它会在 Java 中
  • @delsql 你把这个弄得一团糟。请不要在 cmets 中向答案提出新问题。如果您想要与containsIgnoreCase 不同的东西,那将是一个新问题。
  • Delphi 7 中的 FWIR ContaintsText(由主题启动器提到)仅适用于 LATIN-1 字符集。如果@delsql 想要比较一些国家字符(希腊语、俄语等),他应该改用AnsiContainsText
  • 对于 ContainsText 函数,针是第二个参数,而不是第一个。对于此示例: if ContainsText('A.Sven,G.Jane,Jack', 'Jane') then
猜你喜欢
  • 2020-08-26
  • 1970-01-01
  • 2011-02-05
  • 2014-06-10
  • 2011-02-19
  • 2017-10-15
  • 2014-06-18
相关资源
最近更新 更多