Here is LetterSwap$ Function that actually uses Swap!
Swap also great for scrambling and shuffling!
And once again, @PhilOfPerth Swap needs 2 variables to switch their values. Letter swapping in a string simply involves one variable.
Neither could you: swap "word1", "word2"
Code: (Select All)
a$ = "ABCDEF"
Print "3, 5 "; LetterSwap$(a$, 3, 5)
Print "1, 4 "; LetterSwap$(a$, 1, 4)
Print "4, 2 "; LetterSwap$(a$, 4, 2)
Sub swapLetters (a$, n, m)
t$ = Mid$(a$, n, 1)
Mid$(a$, n, 1) = Mid$(a$, m, 1)
Mid$(a$, m, 1) = t$
End Sub
Function LetterSwap$ (a$, n, m)
Dim L$(1 To Len(a$))
For i = 1 To Len(a$)
L$(i) = Mid$(a$, i, 1)
Next
Swap L$(n), L$(m)
rtn$ = Space$(Len(a$))
For i = 1 To Len(a$)
Mid$(rtn$, i, 1) = L$(i)
Next
LetterSwap$ = rtn$
End Function
Swap also great for scrambling and shuffling!
And once again, @PhilOfPerth Swap needs 2 variables to switch their values. Letter swapping in a string simply involves one variable.
Neither could you: swap "word1", "word2"
b = b + ...