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}}==

{{works with|QBasic|1.1}}
==={{header|Applesoft BASIC}}===
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">function reverse$(a$)
<syntaxhighlight lang="applesoftbasic">10 A$ = "THE FIVE BOXING WIZARDS JUMP QUICKLY"
20 GOSUB 100REVERSE
b$ = ""
30 PRINT R$
for i = 1 to len(a$)
40 END
b$ = mid$(a$, i, 1) + b$

next i
100 REMREVERSE A$
reverse$ = b$
110 R$ = ""
end function</syntaxhighlight>
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}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">function reverse$(a$)
b$ = ""
for i = 1 to len(a$)
b$ = mid$(a$, i, 1) + b$
next i
reverse$ = b$
end function</syntaxhighlight>


==={{header|Sinclair ZX81 BASIC}}===
==={{header|Sinclair ZX81 BASIC}}===