Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alphabetical sort of characters within a string.
#5
If you didn't want to use a sort routine then I think you are correct, you would need each letter to be its own variable and force the combinations which you are looking for. A Select Case could help in the forced combinations. Here is an example of what I mean. Just an example of the concept because you will see this routine comes up with multiple duplications which needs to be addressed and corrected but you get the idea.

Code: (Select All)
Screen _NewImage(1000, 500, 32)

A$ = "A": B$ = "B": C$ = "C": D$ = "D"
Main$ = A$ + B$ + C$ + D$
Print Main$
For a = 1 To 4: Main$ = B$ + C$ + D$ + A$: Next
Print Main$
For b = 1 To 4: Main$ = C$ + D$ + A$ + B$: Next
Print Main$
For c = 1 To 4: Main$ = D$ + A$ + B$ + C$: Next
Print Main$
For d = 1 To 4: Main$ = A$ + B$ + C$ + D$: Next
Print Main$


For a = 1 To 4
    SC = a

    Select Case SC
        Case a
            Main$ = A$ + B$ + C$ + D$
            Print Main$; ":";
        Case b
            Main$ = A$ + B$ + D$ + C$
            Print Main$; ":";
        Case c
            Main$ = A$ + C$ + B$ + D$
            Print Main$; ":";
        Case d
            Main$ = A$ + C$ + D$ + B$
            Print Main$; ":";

    End Select




    For b = 1 To 4
        SC = b
        Select Case SC
            Case a
                Main$ = B$ + A$ + C$ + D$
                Print Main$; ":";
            Case b
                Main$ = B$ + A$ + D$ + C$
                Print Main$; ":";
            Case c
                Main$ = B$ + D$ + A$ + C$
                Print Main$; ":";
            Case d
                Main$ = B$ + D$ + C$ + A$
                Print Main$; ":";


        End Select



        For c = 1 To 4
            SC = c
            Select Case SC
                Case a
                    Main$ = C$ + A$ + B$ + D$
                    Print Main$; ":";
                Case b
                    Main$ = C$ + A$ + D$ + B$
                    Print Main$; ":";
                Case c
                    Main$ = C$ + D$ + A$ + B$
                    Print Main$; ":";
                Case c
                    Main$ = C$ + D$ + B$ + A$
                    Print Main$; ":";

            End Select



            For d = 1 To 4
                SC = d
                Select Case SC
                    Case a
                        Main$ = D$ + A$ + B$ + C$
                        Print Main$; ":";
                    Case b
                        Main$ = D$ + A$ + C$ + B$
                        Print Main$; ":";
                    Case c
                        Main$ = D$ + C$ + A$ + B$
                        Print Main$; ":";
                    Case d
                        Main$ = D$ + C$ + B$ + C$
                        Print Main$; ":";
                End Select
            Next
        Next
    Next
Next
Reply


Messages In This Thread
RE: Alphabetical sort of characters within a string. - by Dimster - 04-24-2024, 03:18 PM



Users browsing this thread: 4 Guest(s)