Einzelnen Beitrag anzeigen

marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#3

Re: Jump to Next Zeile // Replace Prozedur oder Add Leerzeic

  Alt 29. Apr 2006, 17:34
Hi.

Damit auch wirklich jede Zelle untersucht wird, musst du natürlich auch den Spalten- und Zeilenindex richtig setzen:

Delphi-Quellcode:
procedure StringGridReplace(sg: TSTringGrid; const sFrom, sTo: String);
var
  iCol, iRow: Integer;
begin
  with sg do
    for iCol := FixedCols to Pred(ColCount) do
      for iRow := FixedRows to Pred(RowCount) do
        Cells[iCol, iRow] := ReplaceAll(Cells[iCol, iRow], sFrom, sTo);
end;
Statt meiner Funktion ReplaceAll() kannst du auch StringReplace() aus der Unit SysUtils verwenden.

Grüße vom marabu

Nachtrag: Falls es mal wieder länger dauert ist ReplaceAll() vielleicht doch schneller:

Delphi-Quellcode:
// uses Types;

function ReplaceAll(const s, sFrom, sTo: String): String;
var
  ida: TIntegerDynArray;
  i, iIn, iOut, iPos, iLength: Integer;
begin
  ida := FindAll(s, sFrom);
  iLength := Length(s) + Length(ida) * (Length(sTo) - Length(sFrom));
  SetLength(Result, iLength);
  iIn := 1;
  iOut := 1;
  for i := Low(ida) to High(ida) do
  begin
    iPos := ida[i];
    iLength := iPos - iIn;
    Move(s[iIn], Result[iOut], iLength);
    Inc(iOut, iLength);
    Move(sTo[1], Result[iOut], Length(sTo));
    Inc(iOut, Length(sTo));
    Inc(iIn, iLength + Length(sFrom));
  end;
  if iIn <= Length(s) then
    Move(s[iIn], Result[iOut], Succ(Length(s) - iIn));
end;
Und hier noch FindAll():

Delphi-Quellcode:
// uses Types, StrUtils;

function FindAll(const s, substr: String): TIntegerDynArray;
var
  iPos: Integer;
begin
  SetLength(Result, 0);
  iPos := 1;
  repeat
    iPos := PosEx(substr, s, iPos);
    if iPos > 0 then
    begin
      SetLength(Result, Succ(Length(Result)));
      Result[High(Result)] := iPos;
      Inc(iPos, Length(substr));
    end
  until iPos = 0;
end;
  Mit Zitat antworten Zitat