文本所有数字相加

function GetNumSumFromStr(Str: string): Integer;
    function IsNumber(SoureChar: Char): Boolean;
    begin
      Result := False;
      if (Ord(SoureChar) >= 48) and (Ord(SoureChar) <= 57) then
        Result := True;
    end;

    function AddNum(SearthStr: string): string;
    var
      I: Integer;
    begin
      Result := '';
      I := 1;
      while(IsNumber(SearthStr[I]))do
      begin
       Result := Result + SearthStr[I];
       Inc(I);
      end;
    end;
var
I: Integer;
Sum: Integer;
Temp: string;
begin
Result := 0;
I := 1 ;
while I <= Length(Str) do
begin
    if (i <> Length(Str)) and (IsNumber(str[i])) then
    begin
      Temp := AddNum(Copy(Str, I, Length(Str)));
      Result := Result + StrToInt(Temp);
      Inc(I, Length(Temp) + 1);
    end else
      Inc(i);
end;
end;

你可能感兴趣的:(数字)