Author Topic: function GetPiece2(text,pos:string;num:integer):string;  (Read 3196 times)

0 Members and 1 Guest are viewing this topic.

Offline soldat-game

  • Camper
  • ***
  • Posts: 407
function GetPiece2(text,pos:string;num:integer):string;
« on: July 24, 2016, 12:36:29 pm »
If  you need a getpiece function in script core III

Code: [Select]
function GetPiece2(text,pos:string;num:integer):string;
var i,findpos,pos1: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
Result:=Copy(text,pos1,i-pos1);
exit;
end;
end;
end else
begin
if i=length(text) then begin
Result:=Copy(text,pos1,length(text));
exit;
end;
end;
end;
end;