41 lines
1.5 KiB
Text
41 lines
1.5 KiB
Text
arraybase 1
|
|
sString$ = "rosetta code phrase reversal" #The string
|
|
sNewString$ = "" #String variables
|
|
sTemp$ = "" #Temporary string variable
|
|
siCount = 0 #Counter
|
|
dim sWor$(100) #Word store
|
|
i = 0 #Index variable
|
|
|
|
# Loop backwards through the string
|
|
for siCount = length(sString$) to 1 step -1
|
|
sNewString$ += mid(sString$, siCount, 1) #Add each character to the new string
|
|
next
|
|
|
|
print "Original string => " + sString$ #Print the original string
|
|
print "Reversed string => " + sNewString$ #Print the reversed string
|
|
|
|
sNewString$ = "" #Reset sNewString$
|
|
|
|
# Split the original string by spaces
|
|
sWor$ = explode(sString$, " ")
|
|
|
|
# Loop backward through each word in sWor$
|
|
for siCount = sWor$[?] to 1 step -1
|
|
sNewString$ += sWor$[siCount] + " " #Add each word to sNewString$
|
|
next
|
|
|
|
print "Reversed order => " + sNewString$ #Print reversed word order
|
|
|
|
sNewString$ = "" #Reset sNewString$
|
|
|
|
# For each word in sWor$
|
|
for i = 1 to sWor$[?]
|
|
sTemp$ = sWor$[i]
|
|
# Loop backward through the word
|
|
for siCount = length(sTemp$) to 1 step -1
|
|
sNewString$ += mid(sTemp$, siCount, 1) #Add the characters to sNewString$
|
|
next
|
|
sNewString$ += " " #Add a space at the end of each word
|
|
next
|
|
|
|
print "Reversed words => " + sNewString$ #Print words reversed
|