12-26-2025, 04:14 AM
(This post was last modified: 12-26-2025, 04:15 AM by PhilOfPerth.)
I often need to swap two sections of a string, as in the snippet below.
Wiki says "The SWAP statement is used to exchange two variable or array element values".
I find I can only do this by using a temporary variable, so I need 3 lines of code instead of 1.
Is a part of a string a variable?
If not, maybe the Wiki could clarify this, to save L-Platers like me a lot of time experimenting?
(This is a very simple example, but others can be more significant).
T$ = "ABCDEFG"
Print T$
Swap mid$(T$,2,1) ,mid$(T$,5,1) <-- this line is not allowed
Print T$
Tmp$ = Mid$(T$, 2, 1)
Mid$(T$, 2, 1) = Mid$(T$, 5, 1)
Mid$(T$, 5, 1) = Tmp$
Print T$
Wiki says "The SWAP statement is used to exchange two variable or array element values".
I find I can only do this by using a temporary variable, so I need 3 lines of code instead of 1.
Is a part of a string a variable?
If not, maybe the Wiki could clarify this, to save L-Platers like me a lot of time experimenting?
(This is a very simple example, but others can be more significant).
T$ = "ABCDEFG"
Print T$
Swap mid$(T$,2,1) ,mid$(T$,5,1) <-- this line is not allowed
Print T$
Tmp$ = Mid$(T$, 2, 1)
Mid$(T$, 2, 1) = Mid$(T$, 5, 1)
Mid$(T$, 5, 1) = Tmp$
Print T$
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) 
Please visit my Website at: http://oldendayskids.blogspot.com/

Please visit my Website at: http://oldendayskids.blogspot.com/

