Online
Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.291 Beiträge
Delphi 12 Athens
|
AW: Zeichenkette Prüfen ob gültige Zahl ohne Umwandeln?
7. Feb 2011, 10:57
Das Einfachste: Val, TryStrToInt, TryStrToFloat, ...
DecimalSeparator
Ansonsten einfach alles nacheinander prüfen und schauen, ob was Richtiges/Falsches drin vorkommt.
Delphi-Quellcode:
Result := False;
i := 1;
if (i <= Length(S)) and (S[i] in ['+', '-']) then
Inc(i);
if (i > Length(S)) or not (S[i] in ['0'..'9']) then
Exit;
while (i <= Length(S)) and (S[i] in ['0'..'9']) do
Inc(i);
if (i <= Length(S)) and (S[i] = DecimalSeparator) then
begin
Inc(i);
if (i > Length(S)) or not (S[i] in ['0'..'9']) then
Exit;
while (i <= Length(S)) and (S[i] in ['0'..'9']) do
Inc(i);
end;
Result := i > Length(S);
Das läßt sich natürlich noch ein bissl hübscher zusammenfassen.
Ein Therapeut entspricht 1024 Gigapeut.
Geändert von himitsu ( 7. Feb 2011 um 11:02 Uhr)
|