inno setup - 从字符串中删除任意子字符串

inno setup - Delete arbitrary substring from a string

我每次都需要删除一个任意的子字符串。例如: ..\HDTP\System\*.u 应该变成 ..\System\*.u and/or ..\New Vision\Textures\*.utx 应该变成 ..\Textures\*.utx。更具体地说:忽略前三个字符,删除后面的任何字符,直到下一个 \ 字符(包括该字符),保持字符串的其余部分不变。你能帮我解决这个问题吗?我知道,我的解释能力是全世界最差的,如果有什么不明白的地方,我会再尝试解释。

这是 Inno Setup 的一些复制和拆分工作,但我在这里为您提供了一个带有一些额外注释的功能。 仔细阅读它,因为它没有经过适当的测试,如果你必须编辑它,你会 必须知道它在做什么 ;)

function FormatPathString(str : String) : String;
var
    firstThreeChars       : String;
    charsAfterFirstThree  : String;
    tempString  : String;
    finalString  : String;
    dividerPosition   : Integer;
begin

  firstThreeChars := Copy(str, 0, 3);                //First copy the first thee character which we want to keep
  charsAfterFirstThree := Copy(str,4,Length(str));   //copy the rest of the string into a new variable
  dividerPosition := Pos('\', charsAfterFirstThree); //find the position of the following '\'
  tempString := Copy(charsAfterFirstThree,dividerPosition+1,Length(charsAfterFirstThree)-dividerPosition);            //Take everything after the position of '\' (dividerPosition+1) and copy it into a temporary string
  finalString := firstThreeChars+tempString;         //put your first three characters and your temporary string together
  Result := finalString;                             //return your final string
end; 

你会这样称呼它

FormatPathString('..\New Vision\Textures\*.utx');

您必须重命名该函数和 var,以使其与您的程序匹配,但我认为这会对您有所帮助。