Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Delphi-News aus aller Welt (https://www.delphipraxis.net/58-delphi-news-aus-aller-welt/)
-   -   Delphi - always full of surprises! (https://www.delphipraxis.net/196794-delphi-always-full-surprises.html)

DP News-Robot 20. Jun 2018 13:00

Delphi - always full of surprises!
 
After all these years, Delphi still surprises me. Apparently, as I found out today (by making a stupid typo), Copy(string, index, position) doesn't require position parameter!

IOW, following two lines do exactly the same:

s := Copy('123456789', 4, 6);
s := Copy('123456789', 4);

Works for arrays, too!

Of course, this is not documented.


See for yourself:


program ProjectCopy;


{$APPTYPE CONSOLE}


{$R *.res}


uses
SysUtils;


var
s1: TArray;


begin
Writeln(Copy('123456789', 4, 6));
Writeln(Copy('123456789', 4));
s1 := ['1', '2', '3'];
Writeln(string.Join(',', Copy(s1, 1, 2)));
Writeln(string.Join(',', Copy(s1, 1)));
Readln;
end.



This code outputs (in Tokyo):


456789
456789
2,3
2,3



I'd suspect that this goes waaaaaay back. I tested string version with XE2 and it works the same as in Tokyo.


[SIZE=-2]--- Published under the Creative Commons Attribution 3.0 license[/SIZE]


Weiterlesen...


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:36 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz