Official Soldat Forums

Server Talk => Scripting Discussions and Help => Topic started by: soldat-game on July 24, 2016, 07:01:15 am

Title: Why copy() bad work
Post by: soldat-game on July 24, 2016, 07:01:15 am
Hello copy dont work for me if im use me function this return me fasola do remi why not fasola?
if im use text[pos2] this return good letter fasol>>>a<<<
Code: [Select]
function GetPiece2(text,pos:string;num:integer):string;
var i,findpos,pos1,pos2:integer;
begin
findpos:=0;
Result:='';
for i := 1 to length(text) do begin
if text[i]=pos then begin
if num=0 then begin
Result:=Copy(text,1,i-1);
exit;
end else
begin
findpos:=findpos+1;
if findpos=num then pos1:=i+1;
if findpos=num+1 then begin
pos2:=i-1; //debug
WriteLn(inttostr(pos2)+' '+text[pos2]); //debug
Result:=Copy(text,pos1,i-1);
exit;
end;
end;
end else
begin
if i=length(text) then begin
Result:=Copy(text,pos1,length(text));
exit;
end;
end;
end;
end;

procedure ActivateServer();
var b: byte; Temp: TStringList; stong:string;
begin
stong := 'Do remi fasola do remi';
WriteLn(GetPiece2(Stong,' ',2)+'-TEST!');
Title: Re: Why copy() bad work
Post by: Falcon` on July 24, 2016, 12:00:15 pm
2nd argument to Copy is length, not last index. It should be i - pos1 - 1.