How to loop through all possible ASCII characters

Hey guys.

I am curious as to how I can loop through all possible words, basically.

I can do something like this:
Make an array of characters of A - Z ASCII(65 - 90)
For ii = 65 To 90
j = j + 1
Char(j) = Chr$(ii)
Next ii
But I can only hard-code for a given length of characters:
For i = 1 to 26
For i2 = 1 to 26
For i3 = 1 to 26
strGeneratedWord = Char(i) & Char(i2) & Char(i3)...
Next i3
Next i2
Next i
The problem with the above code is that it will only loop for a given
number of characters, and only that amount, but you have to hard-code
an extra for-loop or take one away to increase/decrease.

There must be an easier way.

Let's say I wanted to loop through all possible phone numbers...all
I would have to do is just say i = 0 to 9999 and all numbers between
would be every possible 4-digit number.

So let's say I wanted to see every 1 through 10 character word possible:



This is boggling my mind.

Please help!



  • [b][red]This message was edited by Josh Code at 2003-2-20 5:49:57[/red][/b][hr]
    Number base convertion is related to this.
    You can think of a word as a number with the base being 26.
    Start out with the value being 0 (all 'a' characters in the string).
    Create an add procedure to increment (add 1 to) this value. Every time you add 1 to the value you will create a new combination of letters.

    'a' = 0, 'b' = 1, 'c' = 2...'y' = 24, 'z' = 26

    ascii values: 'a' = 97, 'x' = 120, 'z' = 122

    Here is an example in c++ that will print a bunch of different words to the console:
    // used for the cout routine

    #define len1 10
    // define the length of your word

    #define MaxLetter 'z'
    #define MinLetter 'a'
    // define the bounds of the digits
    char TheWord[len1] = "aaaaaaaaa";

    void incValue()
    /* this can be equated to incrementing a decimal number like 128639999 by looping
    from the last digit(farthest right)
    If the digit is less than 9, increment and stop looping.
    else set digit to 0.

    128639999 would become 128640000.
    unsigned char exitloop=1;

    for (int c=len1-2; (c>0)&&(exitloop!=0);c--) // loop from last digit to first digit of the string
    if (TheWord[c]> TheWord;
    return 0;

    I hope that helps.

  • Wow! Thanks a lot for posting that code!
    This is very helpful!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!