Inno Setup中的通配符(测试固定字符串前缀后是否有值)

Wildcard characters in Inno Setup (test if there is any value after fixed string prefix)

Inno Setup 是否有一些通配符?我正在尝试遍历字符串,如果我正在搜索某个值,程序应该 return 1 (我正在使用 Pos() 已经完成我需要的功能),但是我的这里的问题是我正在搜索的字符串部分不是静态的,所以我需要一些通配符,例如 * 可以替换一个或多个字符。

Inno Setup Pascal Script 直到最近才提供模式匹配功能。从 6.1 开始,您可以使用 WildcardMatch function (如@Roman 的答案所示).


如果您受困于旧版本,或者您需要自定义匹配,您可以使用这样的函数:

function AnythingAfterPrefix(S: string; Prefix: string): Boolean;
begin
  Result := 
     (Copy(S, 1, Length(Prefix)) = Prefix) and
     (Length(S) > Length(Prefix));
end;

并像这样使用它:

if AnythingAfterPrefix(S, 'Listing connections...') then

您可能需要添加 TrimRight 以忽略尾随空格:

if AnythingAfterPrefix(TrimRight(S), 'Listing connections...') then

类似问题:

  • Regular expression for string in Inno Setup
  • Basic email validation within Inno Setup script

根据documentation现在有

function IsWildcard(const Pattern: String): Boolean;
function WildcardMatch(const Text, Pattern: String): Boolean;

可能是最近添加的。应该做你需要的。