Advertisement
mixster

mixster

Jan 14th, 2009
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.82 KB | None | 0 0
  1. procedure AddString(var s: string; a: string);
  2. var
  3.   i, t, o: Integer;
  4.   n: Boolean;
  5.   m: string;
  6. begin
  7.   if Length(s) < Length(a) then
  8.     exit;
  9.  
  10.   n := false;
  11.   o := Length(s) - Length(a);
  12.   for i := Length(a) downto 1 do
  13.   begin
  14.     t := StrToIntDef(Copy(s, i + o, 1), 0);
  15.     t := t + StrToIntDef(Copy(a, i, 1), 0);
  16.     if n then
  17.     begin
  18.       t := t + 1;
  19.       n := false;
  20.     end;
  21.     if t >= 10 then
  22.     begin
  23.       n := true;
  24.       t := t mod 10;
  25.     end;
  26.     m := IntToStr(t);
  27.     s[i + o] := m[1];
  28.   end;
  29.  
  30.   if n and (o > 0) then
  31.   begin
  32.     t := StrToIntDef(Copy(s, 1, o), 0);
  33.     t := t + 1;
  34.     m := IntToStr(t);
  35.     if Length(m) > o then
  36.     begin
  37.       s := '0' + s;
  38.       o := o + 1;
  39.     end;
  40.     for i := 1 to o do
  41.       s[i] := m[i];
  42.   end
  43.   else if n then
  44.     s := '1' + s;
  45. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement