Christian Bockermann wrote:
(By the way, if you have suggestions for a better style of programming this copy-function, please let me know, I'm already learning ... :-)
In this case, there is quite an easy option: you can use EP(Extended Pascal)'s SubStr function. Incidentally, I just wrote a Copy function on Monday, including some checks for strange situations.
Here it is (as in your example, TStr can be any string[n], but not string):
function Copy(const s:String;Index,Count:Integer):TStr; begin if Index<1 then begin Dec(Count,1-Index); Index:=1 end; if (Index>Length(s)) or (Count<=0) then Copy:='' else if Index+Count-1>Length(s) then Copy:=SubStr(s,Index,Length(s)-Index+1) else Copy:=SubStr(s,Index,Count) end;
Frank
-- Frank Heckenbach, Erlangen, Germany heckenb@mi.uni-erlangen.de http://home.pages.de/~fjf/links.htm