inno setup - Delete arbitrary substring from a string

George Hovhannisian

I need to delete a substring which is arbitrary each time. For example: ..\HDTP\System\*.u should become ..\System\*.u and/or ..\New Vision\Textures\*.utx should become ..\Textures\*.utx. More specifically: Ignore the first three characters, delete whatever comes after, until the next \ character (including that character), leave the rest of the string intact. Could you, please, help me with this? I know, I have the worst explaining skills in the whole world, if something isn't clear, I'll try to explain again.

Bongo

This is a little bit of copy and split work for Inno Setup but I have here a function for you with some extra comments. Read it carefully as it isn't tested properly and if you have to edit it you will have to know what it is doing ;)

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 this is how you would call it

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

You will have to rename the function and the var's so that it will match your program but I think this will help you.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Inno Setup: Delete empty lines from test file

From Dev

Delete a substring from a string with a filename in Perl

From Dev

Convert Boolean to String with Inno Setup

From Dev

How to split a string in Inno Setup

From Dev

Inno Setup loop from A to Z

From Dev

How to delete a nonempty folder in inno setup

From Dev

Should Inno Setup delete old files on Update?

From Dev

Inno Setup: Delete folder with Task function

From Dev

Should Inno Setup delete old files on Update?

From Dev

How to parse a JSON string in Inno Setup?

From Dev

Inno Setup: Exec can't read string?

From Dev

Inno setup: how to replace a string in XML file?

From Dev

Convert Single data type to string in inno setup

From Dev

Inno Setup convert string in array to boolean

From Dev

Returning a string from a C# DLL with Unmanaged Exports to Inno Setup script

From Dev

How do I return a string from DLL to Inno Setup Pascal Script

From Dev

Returning a string from a C# DLL with Unmanaged Exports to Inno Setup script

From Dev

Delete substring in string of PostgreSQL table

From Dev

Import a scheduled task from XML in Inno Setup

From Dev

How to call "npm install" from Inno Setup?

From Dev

Inno Setup create TStringList from CDATA

From Dev

Create ZIP files from within Inno Setup

From Dev

Call Function From Procedure in Inno Setup?

From Dev

Running netsh from using Inno Setup Exec()

From Dev

Prevent button from receiving focus in Inno Setup

From Dev

Inno Setup unzip file from input user

From Dev

Inno Setup [UninstallDelete] delete all except one folder

From Dev

Inno setup uninstaller doesnt delete rewritten registry values

From Dev

SQL substring from a string

Related Related

HotTag

Archive