RosettaCodeData/Task/Phrase-reversals/BASIC256/phrase-reversals.basic
2024-10-16 18:07:41 -07:00

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