String manipulation 
Author Message
 String manipulation

Can anybody help me find a way to get every possible combination of
capital and lower case letters for a string. Here's what I have so far.

OPEN "A.TXT" FOR OUTPUT AS #1
A$ = "abcdef"
FOR i% = 1 TO LEN(A$)
   A1$ = A$
   MID$(A1$, i%, 1) = UCASE$(MID$(A1$, i%, 1))
   PRINT #1, A1$
   FOR j% = i% + 1 TO LEN(A1$)
      A2$ = A1$
      MID$(A2$, j%, 1) = UCASE$(MID$(A2$, j%, 1))
      PRINT #1, A2$
      FOR K% = j% + 1 TO LEN(A1$)
         A3$ = A2$
         MID$(A3$, K%, 1) = UCASE$(MID$(A3$, K%, 1))
         PRINT #1, A3$
      NEXT K%
   NEXT j%
NEXT i%

Of course I would need to nest another 3 loops in there to go completely
through every combination, but I'm trying to find a way to do it that
isn't dependent on the length of the string.

Thank you in advance
Rob Rogers



Wed, 01 Aug 2001 03:00:00 GMT  
 String manipulation

Quote:

>Can anybody help me find a way to get every possible combination of
>capital and lower case letters for a string. Here's what I have so far.

<<SNIP>>

Hmm, nice little puzzle.  Here's a way to do it which is not dependent on
the string length (as long as it is less than 30 characters or so).  However
bear in mind that if you use this routine for strings longer than 25
characters you'll need to wait a long time ...

Cheers

Derek

CLS
OPEN "A.TXT" FOR OUTPUT AS #1
A$ = "abcdefg"
FOR i& = 0 TO 2 ^ LEN(A$) - 1
   T$ = LCASE$(A$)
   k& = 1
   FOR j& = 1 TO LEN(A$)
      IF (i& AND k&) <> 0 THEN MID$(T$, j&, 1) = UCASE$(MID$(T$, j&, 1))
      k& = k& + k&
   NEXT j&
   PRINT #1, T$
NEXT i&
CLOSE #1
END



Wed, 01 Aug 2001 03:00:00 GMT  
 String manipulation

Quote:

> Can anybody help me find a way to get every possible
> combination of capital and lower case letters for a string.
> Here's what I have so far.
> OPEN "A.TXT" FOR OUTPUT AS #1
> A$ = "abcdef"
> FOR i% = 1 TO LEN(A$)
>    A1$ = A$
>    MID$(A1$, i%, 1) = UCASE$(MID$(A1$, i%, 1))
>    PRINT #1, A1$
>    FOR j% = i% + 1 TO LEN(A1$)
>       A2$ = A1$
>       MID$(A2$, j%, 1) = UCASE$(MID$(A2$, j%, 1))
>       PRINT #1, A2$
>       FOR K% = j% + 1 TO LEN(A1$)
>          A3$ = A2$
>          MID$(A3$, K%, 1) = UCASE$(MID$(A3$, K%, 1))
>          PRINT #1, A3$
>       NEXT K%
>    NEXT j%
> NEXT i%
> Of course I would need to nest another 3 loops in there to go
> completely through every combination, but I'm trying to find a
> way to do it that isn't dependent on the length of the string.

-----------------------------------------------------------------
It appears you're using uppercase letters to "mark" those letters
selected to be part of a combination.  If this is correct, your
stated goal of "every possible combination of capital and lower
case letters for a string" is at at odds with your code's output.

Combinations can be generated recursively as in:

   DECLARE SUB Comb (C$, l%, cs%, f%)
   DEFINT A-Z
   CONST E$ = "abcdef"
   CLS : n = LEN(E$)
   for r:=1 to 3: C$ = "": CALL Comb((C$), n, r, 1): next r

   SUB Comb (C$, l, cs, f)
     IF cs = 0 THEN
        PRINT C$
        ELSE
        FOR i = f TO l - cs + 1
          CALL Comb(C$ + MID$(E$, i, 1), l, cs - 1, i + 1)
        NEXT i
     END IF
   END SUB

If you really wanted to treat upper and lower case letters as
unique objects, change the value of E$ to include both cases as
in CONST E$ = "abcdefABCDEF".
-----------------------------------------------------------------
Derek Asari



Wed, 01 Aug 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. string manipulation, string routines, etc.

2. String manipulation

3. String Manipulation

4. VBA String Manipulation DLL Missing

5. String manipulation in VBA

6. String Manipulation

7. String manipulation with vbscript

8. String manipulation topic

9. String manipulation...

10. Text String Manipulation

11. Newbie question : string manipulation with VBscript.

12. String manipulation

 

 
Powered by phpBB® Forum Software