Now I am working at big Delpihi project - this program will work with CSV-files and with databases.
And I have a problem - I need a function that can "extract" substring in some position from string.
I mean if I have string=I1want1to1go than my function must return want if I set position=2 and separator=1.
Its like function $p in COS (Cache Object Script).
My programm will work with big files (10MB-100MB). It will get string from file, "extract" data and save in database. So I need a very fast function. Ive created some function, but its not so fast I need. How to optimize it or I should write this function on ASM or C++?
The function I write in "Pascal style" (its a Pascal topic!

Code: Alles auswählen
function piece(s:string;ch:char;p:word):string;
var vr_str:string;sch,i,j:word;
begin
if pos(ch,s) = 0 then piece:=s
else
begin sch:=1;
i:=1;
vr_str:=;
while (s[i]=ch) and (i<=length(s)) do inc(i);
for j:=i to length(s) do
if s[j]<>ch then begin vr_str:=vr_str+s[j];
if j=length(s) then begin piece:=vr_str;
break;
end;
end
else
if sch=p then begin piece:=vr_str;
break;
end
else begin inc(sch);
vr_str:=;
end;
end;
end;
var proba_string:string;
ps:word;
vr_ch:char;
begin
write(Please, input your string: );
readln(proba_string);
write(Input separator: );
readln(vr_ch);
write(Input position (,vr_ch, is separator): );
readln(ps);
writeln(piece(proba_string,vr_ch,ps));
writeln(Press Enter...);
readln;
end.
What can you advice me?...