Einzelnen Beitrag anzeigen

Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.429 Beiträge
 
Delphi 10.4 Sydney
 
#20

AW: Spaltennummer nach Excel-Spaltenstring umwandeln.

  Alt 16. Sep 2014, 10:31
Ein schönes Beispiel das man jede Rekursion auch als Iteration darstellen kann oder umgekehrt.
Ich würde die Abbruchbedingung vorher testen, dann gibts auch kein direktes Problem wenn ein Wert <= 0 übergeben wird.
Und die Subtraktion nur einmal.
Delphi-Quellcode:
function XlsCol(col : integer) : String;
begin
  Assert(col > 0, 'Col must be > 0');

  Result := '';
  while col > 0 do
  begin
    col := col - 1;
    Result := chr(65 + col mod 26] + Result;
    col := col div 26;
  end;
end;
  Mit Zitat antworten Zitat