Einzelnen Beitrag anzeigen

moelski

Registriert seit: 31. Jul 2004
1.110 Beiträge
 
Delphi 2010 Professional
 
#12

AW: schnellste Variante für String Reduktion auf 1..9,0 und "." ","

  Alt 18. Aug 2010, 15:04
Das wäre meine Variante:

Delphi-Quellcode:
Function Floaty(Input : String; DezSep : Char) : String;
var c : Char;
    Thousand : Char;
    len : integer;
    Start : Boolean;
    DezSepDone : Boolean;
  procedure Accept(c: char);
  begin
    inc(len);
    Result[len] := c;
  end;
begin
  len := 0; Start := False; DezSepDone := False;

  if DezSep = '.then Thousand := ','
                  else Thousand := '.';

  SetLength(Result, Length(Input));
  for c in Input do begin
    if c in ['0' .. '9', '-', DezSep] then begin
      if (c = DezSep) and DezSepDone then Break; // Bsp : 1.323,999,34 verhindern
      Start := len=0; // Wenn erste Zahl hinzugefügt wird -> Start
      if c = DezSep then begin
        DezSepDone := True; // DezimalSep wurde bearbeitet
        Accept(DecimalSeparator);
      end else
        Accept(c);
    end else begin
      if Start and (c <> Thousand) then Break;
    end;
  end;
  SetLength(Result, len);
end;
Floaty('Dies ist -1,323.999.34 jojo', '.') liefert -1323,999.
Dominik Schmidt
Greetz Dominik

I love Delphi 2007/2010
  Mit Zitat antworten Zitat