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

时间:2015-07-30 21:58:07

标签: inno-setup

我需要删除每次都是任意的子字符串。例如: ..\HDTP\System\*.u应变为..\System\*.u和/或..\New Vision\Textures\*.utx变为..\Textures\*.utx。更具体地说:忽略前三个字符,删除后面的任何字符,直到下一个\字符(包括该字符),保持字符串的其余部分完好无损。请你帮帮我吗?我知道,我在全世界都有最糟糕的解释技巧,如果事情不清楚,我会再试一次。

1 个答案:

答案 0 :(得分:4)

这是Inno安装程序的一些复制和拆分工作,但我在这里有一些函数给你一些额外的评论。 仔细阅读,因为没有正确测试,如果你必须编辑,你会 必须知道它在做什么;)

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,以便它与您的程序匹配,但我认为这会对您有所帮助。