Board index » delphi » Newbie needing help. Code for string generation

Newbie needing help. Code for string generation

Hi All,
  I'm new to this group and I don't know if I can ask this sort of question.
If I can't then I apoligise and won't do it again.  I'm using Delphi 2 and
trying to write a bit of code to generate strings like the following....

a
b
c
d
etc.....

then
aa
ab
ac
ad
etc....

aaa
aab
etc...

I think you get the idea. THe only way I've done it so far is using nested
for...next loops but this is really messy and I want to be able to define
the depth.  Anyone got any sample code or know where I can get some to do
this? TIA

Rus

 

Re:Newbie needing help. Code for string generation


{question snipped}

Since you are using Delphi, your question is not really appropriate in this
comp.lang.PASCAL.Borland newsgroup.  However, the algorithms are universal,
so here's my suggestion as to how to approach your problem:

Use recursion.  You'll need a procedure that takes 3 parameters:  last
character printed, length of last string printed, and max length of string.
Every time the procedure is called, you'll have to check if you are done by
comparing the length of string you printed last to the max. length of
string, and the last character printed to "z".  If you are not done, print
the character following the one passed to you (if the one passed to you was
"z" you'll have to set the character to "a" and increase the "length of last
string printed" by one).

Hope this helps.

Nikita.

Other Threads