lets see...
I couldn't use a TStringList because there is no direct access pointer to actual string list, the GetText and TEXT properties recreates the string so that's a bust, also its kind of a waste of processing speed, there should be a way to get the raw text and then call a method to have the stringlist update itself if values were changed directly..
But in anycase, I did an example using a TmemoryStream, the stream can be used to load the file and then filter out the blank lines quickly. after that you assign the Memory space over to a TstingList if you want to use the facilities of that..
Procedure RemoveEmptyLines( Var S:TMemorystream);
var
R,W,ST:Pchar;
CC,LEC:Integer;
Begin
If (S = Nil)or(S.Size=0) then Exit;
R := PChar(S.Memory);
W := R;
ST := W;
While R^<>#0 do
Begin
CC := 0; //Char Count;
While Not (R^ in [#13,#10,#0]) do //Move line content if any
Begin
W^ := R^;
Inc(R); Inc(W);
Inc(CC);
End;
If CC <> 0 Then
Begin
LEC := 0;
While (R^ in [#13,#10])and(LEC<2) Do //Move the Line Ending if Valid content.
Begin
Inc(LEC);
W^:= R^;
Inc(R);
Inc(W);
end;
End
Else
While (R^ in [#13,#10]) Do Inc(R); // Skip over blanks.
End;
W^ := #0; // Terminate the end;..
End;
procedure TForm1.Button1Click(Sender: TObject);
Var
S:TMemoryStream;
P:PChar;
begin
//Test code;
S := TmemoryStream.Create; //you can load from file here.
S.Write(Pchar(Memo1.Lines.Text)^,Length(Memo1.Lines.Text)+1); //use a memo for now to create test data.
RemoveEmptyLines(S); // The real work horse;
Memo1.Lines.Text :=String(S.Memory);
S.Free;
end;
I need to work out the Line Ending issue incase there are repeating single type line endings. I can work that out later I guess.. but This works like streak Lighting compare to others..