Phrase reversals: Difference between revisions

no edit summary
(→‎{{header|Python}}: Less boilerplate)
No edit summary
Line 868:
Reversed words => attesor edoc esarhp lasrever
Reversed order => reversal phrase code rosetta
</pre>
 
=={{header|Gambas}}==
<lang gambas>Public Sub Main()
Dim sString As String = "rosetta code phrase reversal" 'The string
Dim sNewString, sTemp As String 'String variables
Dim siCount As Short 'Counter
Dim sWord As New String[] 'Word store
 
For siCount = Len(sString) DownTo 1 'Loop backwards through the string
sNewString &= Mid(sString, sicount, 1) 'Add each character to the new string
Next
 
Print "Original string = \t" & sString & "\n" & 'Print the original string
"Reversed string = \t" & sNewString 'Print the reversed string
 
sNewString = "" 'Reset sNewString
 
For Each sTemp In Split(sString, " ") 'Split the original string by the spaces
sWord.Add(sTemp) 'Add each word to sWord array
Next
 
For siCount = sWord.max DownTo 0 'Loop backward through each word in sWord
sNewString &= sWord[siCount] & " " 'Add each word to to sNewString
Next
 
Print "Reversed word order = \t" & sNewString 'Print reversed word order
 
sNewString = "" 'Reset sNewString
For Each sTemp In sWord 'For each word in sWord
For siCount = Len(sTemp) DownTo 1 'Loop backward through the word
sNewString &= Mid(sTemp, siCount, 1) 'Add the characters to sNewString
Next
sNewString &= " " 'Add a space at the end of each word
Next
 
Print "Words reversed = \t" & sNewString 'Print words reversed
 
End</lang>
Output:
<pre>
Original string = rosetta code phrase reversal
Reversed string = lasrever esarhp edoc attesor
Reversed word order = reversal phrase code rosetta
Words reversed = attesor edoc esarhp lasrever
</pre>
 
Anonymous user