"Segment fault" error :-(_(re)

Thu, 9 Oct 1997 16:34:36 +0200



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


Frank Heckenbach (heckenb@mi.uni-erlangen.de)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es