Inno setup - Remove arbitrary substring from string
I need to remove a substring that is arbitrary every time. For example:
..\HDTP\System\*.u
must become ..\System\*.u
and / or ..\New Vision\Textures\*.utx
must become ..\Textures\*.utx
. More specifically: Ignore the first three characters, remove whatever comes after, until the next character \
(including that character) leave the rest of the line intact. Could you help me with this? I know I have the worst explaining skills in the whole world, if something is not clear I will try to explain again.
source to share
This is a small copy and split work for Inno Setup, but I have a function for you with some additional comments. Please read it carefully as it is not validated correctly and if you need to edit it you will need to know what it does;)
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;
And that's how you would call him
FormatPathString('..\New Vision\Textures\*.utx');
You will need to rename the function and var to match your program, but I think this will help you.
source to share