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->a ba
the string's low and up case is not required.
like this:
aaa->aab->aac->...->aaz->a
the string's low and up case is not required.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
Inc(str[p])
instead of
str[p] := char(ord(str[p])+1)
Regards
Paul