1
0
mirror of synced 2024-09-19 17:56:09 +00:00

Added: ReplacePart function

This commit is contained in:
Mark van Renswoude 2005-06-28 13:06:16 +00:00
parent 8374bc2fee
commit 7edc96e0a4

View File

@ -114,9 +114,13 @@ type
function ChildPathEx(var AChild, AParent: String; function ChildPathEx(var AChild, AParent: String;
const AFailIfSame: Boolean = False): Boolean; const AFailIfSame: Boolean = False): Boolean;
function ReplacePart(const ASource: String; const AStart, ALength: Integer;
const AReplace: String): String;
implementation implementation
uses uses
SysUtils; SysUtils,
Windows;
function FormatSize(const ABytes: Int64; AKeepBytes: Boolean = False): String; function FormatSize(const ABytes: Int64; AKeepBytes: Boolean = False): String;
const const
@ -379,5 +383,35 @@ begin
(Length(AChild) > Length(AParent))); (Length(AChild) > Length(AParent)));
end; end;
function ReplacePart(const ASource: String; const AStart, ALength: Integer;
const AReplace: String): String;
var
iSrcLength: Integer;
iLength: Integer;
iDiff: Integer;
iDest: Integer;
begin
iSrcLength := Length(ASource);
iLength := Length(AReplace);
iDiff := iLength - ALength;
iDest := 1;
SetLength(Result, iSrcLength + iDiff);
// Write first part
CopyMemory(@Result[iDest], @ASource[1], AStart - 1);
Inc(iDest, AStart - 1);
// Write replacement
CopyMemory(@Result[iDest], @AReplace[1], iLength);
Inc(iDest, iLength);
// Write last part
CopyMemory(@Result[iDest], @ASource[AStart + ALength],
iSrcLength - AStart - (ALength - 1));
end;
end. end.