Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 138

# 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.
0
Sam80
1 Solution

Commented:
var
i,p: integer;
str: string;
begin
str := 'aaa';
p := length(str);
while str <> 'aba' do begin
if str[p] <> 'z' then
str[p] := char(ord(str[p])+1)
else begin
str[p] := 'a';
dec(p);
str[p] := char(ord(str[p])+1)
end;
end;
end;
0

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

Regards
Paul
0

Commented:
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
0

## Featured Post

Tackle projects and never again get stuck behind a technical roadblock.