Reverse a string: Difference between revisions
Content added Content deleted
(→{{header|Applesoft BASIC}}: move under BASIC heading) |
(→{{header|BASIC}}: Sort entries; add Commodore BASIC 3.5+ implementation) |
||
Line 551: | Line 551: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
⚫ | |||
==={{header|Applesoft BASIC}}=== |
|||
⚫ | |||
<syntaxhighlight lang=" |
<syntaxhighlight lang="applesoftbasic">10 A$ = "THE FIVE BOXING WIZARDS JUMP QUICKLY" |
||
20 GOSUB 100REVERSE |
|||
⚫ | |||
30 PRINT R$ |
|||
⚫ | |||
40 END |
|||
⚫ | |||
⚫ | |||
100 REMREVERSE A$ |
|||
⚫ | |||
110 R$ = "" |
|||
⚫ | |||
120 FOR I = 1 TO LEN(A$) |
|||
130 R$ = MID$(A$, I, 1) + R$ |
|||
140 NEXT I |
|||
150 RETURN</syntaxhighlight> |
|||
==={{header|BASIC256}}=== |
==={{header|BASIC256}}=== |
||
Line 575: | Line 579: | ||
{{out}} |
{{out}} |
||
<pre>'asdf' reversed is 'fdsa'</pre> |
<pre>'asdf' reversed is 'fdsa'</pre> |
||
==={{header|Commodore BASIC}}=== |
|||
{{works with|Commodore BASIC|3.5,7.0}} |
|||
Commodore BASIC 3.5 turned MID$ into an lvalue function, and assigning a string of the same length to MID$ replaces the characters instead of allocating a new string, so the reversal can be done in-place: |
|||
<syntaxhighlight lang="basic"> |
|||
100 INPUT "STRING";S$ |
|||
110 FOR I=1 TO INT(LEN(S$)/2) |
|||
120 : J=LEN(S$)+1-I |
|||
130 : T$=MID$(S$,I,1) |
|||
140 : MID$(S$,I,1) = MID$(S$,J,1) |
|||
150 : MID$(S$,J,1) = T$ |
|||
160 NEXT I |
|||
170 PRINT S$</syntaxhighlight> |
|||
{{Out}} |
|||
<pre>STRING? THIS IS A TEST |
|||
TSET A SI SIHT |
|||
READY.</pre> |
|||
==={{header|IS-BASIC}}=== |
==={{header|IS-BASIC}}=== |
||
Line 583: | Line 606: | ||
150 NEXT |
150 NEXT |
||
160 PRINT REV$</syntaxhighlight> |
160 PRINT REV$</syntaxhighlight> |
||
==={{header|QuickBASIC}}=== |
|||
⚫ | |||
⚫ | |||
<syntaxhighlight lang="qbasic">function reverse$(a$) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
==={{header|Sinclair ZX81 BASIC}}=== |
==={{header|Sinclair ZX81 BASIC}}=== |