如何在 Inno Setup 中检查字符串是否以另一个 (EndsWith) 结尾
How to check if a string ends with another (EndsWith) in Inno Setup
我需要在一些 Inno Setup 函数中编写一个逻辑来检查一个字符串是否以另一个结尾。
我可以使用 StrUtils
Pascal 函数 (EndsWith
) 来实现吗?
function NextButtonClick(CurPageID: Integer): Boolean;
var
dir_value: String; app_name: String;
begin
if CurPageID = wpSelectDir then
begin
dir_value := "C:\work\ABC"
app_name := "ABC"
{ I need to write a logic here to check if dir_value ends with app_name }
end;
end;
Inno Setup 中没有 EndsWith
。
但你可以轻松实现它:
function EndsWith(SubText, Text: string): Boolean;
var
EndStr: string;
begin
EndStr := Copy(Text, Length(Text) - Length(SubText) + 1, Length(SubText));
{ Use SameStr, if you need a case-sensitive comparison }
Result := SameText(SubText, EndStr);
end;
虽然在你的情况下,你实际上需要这样的东西:
function EndsWithFileName(FileName, Path: string): Boolean;
begin
Result := SameText(FileName, ExtractFileName(Path));
end;
为SameText
(and SameStr
), you need Inno Setup 6. On older versions, you can replace them with CompareText
(and CompareStr
).
我需要在一些 Inno Setup 函数中编写一个逻辑来检查一个字符串是否以另一个结尾。
我可以使用 StrUtils
Pascal 函数 (EndsWith
) 来实现吗?
function NextButtonClick(CurPageID: Integer): Boolean;
var
dir_value: String; app_name: String;
begin
if CurPageID = wpSelectDir then
begin
dir_value := "C:\work\ABC"
app_name := "ABC"
{ I need to write a logic here to check if dir_value ends with app_name }
end;
end;
Inno Setup 中没有 EndsWith
。
但你可以轻松实现它:
function EndsWith(SubText, Text: string): Boolean;
var
EndStr: string;
begin
EndStr := Copy(Text, Length(Text) - Length(SubText) + 1, Length(SubText));
{ Use SameStr, if you need a case-sensitive comparison }
Result := SameText(SubText, EndStr);
end;
虽然在你的情况下,你实际上需要这样的东西:
function EndsWithFileName(FileName, Path: string): Boolean;
begin
Result := SameText(FileName, ExtractFileName(Path));
end;
为SameText
(and SameStr
), you need Inno Setup 6. On older versions, you can replace them with CompareText
(and CompareStr
).