46 lines
1.8 KiB
Plaintext
46 lines
1.8 KiB
Plaintext
100 sstring$ = "rosetta code phrase reversal" 'The string
|
|
110 snewstring$ = "" 'string variables
|
|
120 stemp$ = "" 'Temporary string variable
|
|
130 sicount = 0 'Counter
|
|
140 dim sword$(100)'Word store
|
|
150 i = 0 'Index variable
|
|
160 startpos = 1 'Start position for word extraction
|
|
170 endpos = 0 'end position for word extraction
|
|
180 wordcount = 0 'Number of words
|
|
190 ' Loop backwards through the string
|
|
200 for sicount = len(sstring$) to 1 step -1
|
|
210 snewstring$ = snewstring$+mid$(sstring$,sicount,1)'Add each character to the new string
|
|
220 next
|
|
230 print "Original string => "+sstring$ 'Print the original string
|
|
240 print "Reversed string => "+snewstring$ 'Print the reversed string
|
|
250 snewstring$ = "" 'Reset sNewString
|
|
260 ' Manually split the original string by spaces
|
|
270 for i = 1 to len(sstring$)
|
|
280 if mid$(sstring$,i,1) = " " or i = len(sstring$) then
|
|
290 if i = len(sstring$) then
|
|
300 endpos = i
|
|
310 else
|
|
320 endpos = i-1
|
|
330 endif
|
|
340 sword$(wordcount) = mid$(sstring$,startpos,endpos-startpos+1)
|
|
350 wordcount = wordcount+1
|
|
360 startpos = i+1
|
|
370 endif
|
|
380 next
|
|
390 ' Loop backward through each word in sWord
|
|
400 for sicount = wordcount-1 to 0 step -1
|
|
410 snewstring$ = snewstring$+sword$(sicount)+" " 'Add each word to sNewString
|
|
420 next
|
|
430 print "Reversed order => "+snewstring$ 'Print reversed word order
|
|
440 snewstring$ = "" 'Reset sNewString
|
|
450 ' For each word in sWord
|
|
460 for i = 0 to wordcount-1
|
|
470 stemp$ = sword$(i)
|
|
480 ' Loop backward through the word
|
|
490 for sicount = len(stemp$) to 1 step -1
|
|
500 snewstring$ = snewstring$+mid$(stemp$,sicount,1)'Add the characters to sNewString
|
|
510 next
|
|
520 snewstring$ = snewstring$+" " 'Add a space at the end of each word
|
|
530 next
|
|
540 print "Reversed words => "+snewstring$ 'Print words reversed
|