Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.184 Beiträge
Delphi 12 Athens
|
AW: schnellste Variante für String Reduktion auf 1..9,0 und "." ","
18. Aug 2010, 15:37
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
Delete(S, 1, i - 1);
Break;
end;
Val(S, Result, i);
end;
und nun noch'n bissl aufgemotzt
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;
$2B or not $2B
|
|
Zitat
|