Compare length of two strings: Difference between revisions
Content added Content deleted
(Added Forth entry) |
|||
Line 317: | Line 317: | ||
call comp("abcd", "123456789")</syntaxhighlight> |
call comp("abcd", "123456789")</syntaxhighlight> |
||
</syntaxhighlight> |
|||
==={{header|GWBASIC}}=== |
|||
Works with BASICA |
|||
Works with QBASIC |
|||
<syntaxhighlight lang="basic"> |
|||
10 'SAVE "SSTRING",A |
|||
20 ' Length of a group of strings |
|||
30 CLS |
|||
40 OPTION BASE 1 |
|||
50 DIM SSTRING$(10) |
|||
60 I=0: J=1 |
|||
70 ' Do |
|||
80 PRINT "Capture the string";J;"(up to 10, Enter to finish)"; |
|||
90 INPUT SSTRING$(J) |
|||
100 IF SSTRING$(J)="" THEN 150 ' Exit Do |
|||
110 IF J>1 THEN GOSUB 250 ' Autosort |
|||
120 J = J + 1 |
|||
130 IF J < 11 THEN 70 ' Loop |
|||
150 ' Show results |
|||
160 CLS |
|||
170 J = J - 1 |
|||
180 IF J<1 THEN PRINT "You entered no strings.": GOTO 230 |
|||
190 PRINT "You entered";J;"strings. Lengths are as follows:" |
|||
200 FOR I=1 TO J |
|||
210 PRINT USING "##. &: ## chars."; I;SSTRING$(I);LEN(SSTRING$(I)) |
|||
220 NEXT I |
|||
230 PRINT: PRINT "End of program execution." |
|||
240 END |
|||
250 ' Autosort subroutine |
|||
260 I=J |
|||
270 WHILE I>1 |
|||
280 IF LEN(SSTRING$(I)) > LEN(SSTRING$(I-1)) THEN SWAP SSTRING$(I), SSTRING$(I-1) |
|||
290 I=I-1 |
|||
300 WEND |
|||
310 RETURN |
|||
</syntaxhighlight> |
|||
==={{header|PureBasic}}=== |
==={{header|PureBasic}}=== |