| Sometimes when a huge path [any long string] is to be displayed in a small space, it is desirable to see the start and the end of the path with ellipses in-between, rather than truncating one of the ends.
For example "C:\Program Files\Delphi\DDropTargetDemomain.pas" is desired to be seen as "C:\Program F....Demomain.pas" then the following "Mince" function could be used. function Mince(PathToMince :String; InSpace :Integer): String;
var TotalLength, FLength : Integer;
begin
TotalLength := Length(PathToMince) ;
if TotalLength > InSpace then
begin
FLength := (Inspace Div 2) - 2;
Result := Copy(PathToMince, 0, fLength)
+ '...'
+ Copy(PathToMince,
TotalLength-fLength,
TotalLength) ;
end
else
Result := PathToMince;
end;
The "InSpace" is an approximate number of charecters the intended space can hold. |