![]() |
AW: schnellste Variante für String Reduktion auf 1..9,0 und "." ","
Delphi-Quellcode:
und nun noch'n bissl aufgemotzt
function GetNum(S: String): Extended;
var i: Integer; begin Result := 0; for i := 1 to Length(S) do if S[i] in ['0'..'9'] then begin Delete(S, 1, i - 1); Break; end; Val(S, Result, i); end;
Delphi-Quellcode:
function GetNum(S: String): Extended;
var i: Integer; begin Result := 0; for i := 1 to Length(S) do if S[i] in ['0'..'9'] then begin if (i > 1) and (S[i - 1] in ['+', '-']) then Delete(S, 1, i - 2) else Delete(S, 1, i - 1); Break; end; S := StringReplace(S, ',', DecimalSeparator, [rfReplaceAll]); Val(S, Result, i); end; |
AW: schnellste Variante für String Reduktion auf 1..9,0 und "." ","
Das wäre meine Variante:
Delphi-Quellcode:
Floaty('Dies ist -1,323.999.34 jojo', '.') liefert -1323,999.
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; |
AW: schnellste Variante für String Reduktion auf 1..9,0 und "." ","
Zitat:
Delphi-Quellcode:
Damit passt das für ANSI, UNICODE und 64 Bit, 128 Bit, ... man weiß ja nie.
SetLength( str, (p2 - PChar(str)) );
|
AW: schnellste Variante für String Reduktion auf 1..9,0 und "." ","
Hallo,
@moelski: Hänge doch bitte eine Beispieldatei an, damit man eine Tempovergleich der verschiedenen Versionen machen kann. Gruß Horst |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:18 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