gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 10:00:53 25 4
gpt4 key购买 nike

我每次都需要删除一个任意的子字符串。例如:..\HDTP\System\*.u 应该变成 ..\System\*.u 和/或 ..\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,以便它与您的程序匹配,但我认为这会对您有所帮助。

关于inno-setup - inno setup - 从字符串中删除任意子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31734801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com