AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi Add Leerzeichen nach gelöschten POS?
Thema durchsuchen
Ansicht
Themen-Optionen

Add Leerzeichen nach gelöschten POS?

Ein Thema von danku · begonnen am 29. Apr 2006 · letzter Beitrag vom 1. Mai 2006
Antwort Antwort
marabu

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

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
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:35 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz