So, what I’m trying to do this something like this: (example)
a,b,c,d.. etc. aa,ab,ac.. etc. ba,bb,bc, etc.
So, this can essentially be explained as generally increasing and just printing all possible variations, starting at a. So far, I’ve been able to do it with one letter, starting out like this:
for (int i = 97; i <= 122; i++)
{
item = (char)i
}
But, I’m unable to eventually add the second letter, third letter, and so forth. Is anyone able to provide input? Thanks.
Since there hasn’t been a solution so far that would literally “increment a string”, here is one that does:
The idea is simple: pretend that letters are your digits, and do an increment the way they teach in an elementary school. Start from the rightmost “digit”, and increment it. If you hit a nine (which is
'z'in our system), move on to the prior digit; otherwise, you are done incrementing.The obvious special case is when the “number” is composed entirely of nines. This is when your “counter” needs to roll to the next size up, and add a “digit”. This special condition is checked at the beginning of the method: if the string is composed of
Nletters'z', a string ofN+1letter'a's is returned.Here is a link to a quick demonstration of this code on ideone.