Link to home
Start Free TrialLog in
Avatar of Sam80
Sam80

asked on

How to increase a string ?

for example , the initial string is 'aaa', the final string is 'aba', i want to increase the initial sting 'aaa' letter by letter to the final string 'aba',
like this:

aaa->aab->aac->...->aaz->aba

the string's low and up case is not required.
ASKER CERTIFIED SOLUTION
Avatar of SimesA
SimesA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zebada
zebada

You can also use:
  Inc(str[p])
instead of
  str[p] := char(ord(str[p])+1)

Regards
Paul
Here's another way that emulates modulo 26 arithmetic (like an extended form of HEX)

str:='aaa';
carry:=false;
for ol:=3 downto 1 do //change 1 to 2 if only 2 characters
 for l:= 1 to 26 do   //are required to be changed
   begin
    if carry then
     str[ol+1]:='a';
    str[ol]:=char(l+96);
    carry:=(l mod 26)=0;
   end;

Regards
Roger Fedyk