Другие языки программирования и технологии

Помогите с задачей, пожалуйста! (Delphi) Дана строка символов, состоящая из букв, цифр, запятых, точек, знаков "+" и "-

function IsDigit(Ch: Char): Boolean;
begin
Result := Ch in ['0'..'9'];
end;
function IsSign(Ch: Char): Boolean;
begin
Result := (Ch = '+') or (Ch = '-');
end;
function IsSeparator(Ch: Char): Boolean;
begin
Result := Ch= '.';
end;
function IsExponent(Ch: Char): Boolean;
begin
Result := (Ch = 'E') or (Ch = 'e');
end;
function IsNumber(const S: string): Boolean;
var
P: Integer;
begin
Result := False;
if Length(S) = 0 then
Exit;
P := 1;
if IsSign(S[P]) then
Inc(P);
if (P > Length(S)) or not IsDigit(S[P]) then
Exit;
repeat
Inc(P);
until (P > Length(S)) or not IsDigit(S[P]);
if P > Length(S) then
begin
Result := True;
Exit;
end;
if IsSeparator(S[P]) then
begin
Inc(P);
if (P > Length(S)) or not IsDigit(S[P]) then
Exit;
repeat
Inc(P);
until (P > Length(S)) or not IsDigit(S[P]);
if P > Length(S) then
begin
Result := True;
Exit;
end;
end;

if IsExponent(S[P]) then
begin
Inc(P);
if P > Length(S) then
Exit;
if IsSign(S[P]) then
Inc(P);
if (P > Length(S)) or not IsDigit(S[P]) then
Exit;
repeat
Inc(P);
until (P > Length(S)) or not IsDigit(S[P]);
if P > Length(S) then
begin
Result := True;
Exit;
end;
end;
end;
ВI
Владимир I
2 052
Лучший ответ
Для этих целей замечательно подходит такая вещь, как regular expressions. Почитай про это дело, поставь библиотеку RegEx (если ее вдруг у тебя нет) и вперед.
Айбек Ражапов
Айбек Ражапов
99 943
пиши в аську 1 695 2 7 143