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
  • Last Modified:

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
Asked:
Sam80
1 Solution
 
SimesACommented:
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;
    Listbox1.Items.Add(str);
  end;
end;
0
 
zebadaCommented:
You can also use:
  Inc(str[p])
instead of
  str[p] := char(ord(str[p])+1)

Regards
Paul
0
 
rfedykCommented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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