【问题标题】:Case-sensitive MatchesMask alternative in DelphiDelphi 中区分大小写的 MatchesMask 替代方案
【发布时间】:2021-10-25 15:50:17
【问题描述】:

我使用下面的代码来检测所需的文件:

uses Masks;
 
begin
  if MatchesMask(MyFilename, '*.Exe') then
  begin
    // Do Something
  end;
end;

但是,如 the official documentation 中所述,MatchesMask 不区分大小写。

是否有任何区分大小写的方法来使用通配符检测文件名? (我使用的是 Delphi 10.3.3 VCL)

【问题讨论】:

  • 无论如何:如果您只检查特定的后缀,那么您可以立即使用if Copy( MyFilename, Length( MyFilename )- 3, 4 )= '.Exe'
  • @AmigoJack:我会写MyFilename.EndsWith('.Exe')
  • @AmigoJack 或if ExtractFileExt(MyFilename) = '.Exe' then docwiki.embarcadero.com/Libraries/en/…
  • 我很好奇所有这些人在幕后做了什么(以及它们有多强大)......
  • 他们是delphi中的正则表达式工具,如果我没记错的话是Tregex

标签: delphi delphi-10.3-rio


【解决方案1】:

这样好吗?

也许你可以做到这一点。全部转换为大写。

uses Masks;
 
begin
  if MatchesMask(Upper(MyFilename)), Upper('*.Exe')) then
  begin
    // Do Something
  end;
end;

【讨论】:

  • 它已经不区分大小写了。我要区分大小写。
猜你喜欢
  • 1970-01-01
  • 2010-09-19
  • 1970-01-01
  • 2010-10-29
  • 2012-03-05
  • 2013-10-19
  • 2011-08-05
  • 2017-02-01
相关资源
最近更新 更多