Split a string: needed efficient algoritme
Posted on 1998-06-07
Having no time to do this myself right now,
I would like to have the following slow code modified so that it becomes
much, much quicker.
Function Reserve can go away, but the procedure SplitFromEnd must give the exact same result as it does know.
The typical length of the string to process in SplitFromEnd is about 20 Kb.
So Reserve is very very inefficient.
Please post your answer ASAP, and in the form of a procedure I can cut and paste
in my program right away and do not give mere hints.
Function Reverse(Inputstring: String): String;
var x : integer;
ToProcess : String;
for x:= 1 to length(Inputstring)
do ToProcess:= copy(Inputstring,x,1) + ToProcess;
procedure SplitFromEnd(SplitAt: String; var InputString, PostString: String) ;
var TmpPos: integer;
Before, AfterIncl, ToProcess: String;
TmpPos := pos(tmpSplitAt, ToProcess);
if tmppos = 0
MessageDlg('SplitFromEnd: NOT FOUND', mtInformation,[mbOk], 0);
AfterIncl:= copy(ToProcess, 1, tmppos + length(SplitAt));
Before := copy(ToProcess, tmppos +length(SplitAt), length(ToProcess));
Before := reverse(Before);