Reverse words in a string: Difference between revisions

no edit summary
No edit summary
Line 1,231:
=={{header|Gema}}==
<lang gema>\L<G> <U>=@{$2} $1</lang>
 
=={{header|Gambas}}==
<lang gambas>Public Sub Form_Open()
Dim sString As New String[10] 'Array for the input text
Dim sLine As New String[] 'Array of each word in a line
Dim siCount0, siCount1 As Short 'Counters
Dim sOutput, sReverse, sTemp As String 'Strings
 
sString[0] = "---------- Ice And Fire ------------" 'Input text
sString[1] = " "
sString[2] = "fire, in end will world the say Some"
sString[3] = "ice. in say Some "
sString[4] = "desire of tasted I've what From "
sString[5] = "fire. favor who those with hold I "
sString[6] = " "
sString[7] = "... elided paragraph last ... "
sString[8] = " "
sString[9] = "Frost Robert -----------------------"
 
For siCount0 = 0 To 9 'To work through each line of input text
If Trim(sString[siCount0]) = "" Then sString[siCount0] = " " 'If the line is all spaces then make it 1 space
For Each sTemp In Split(Trim(sString[siCount0]), " ") 'Split the trimmed line by spaces
sLine.Add(sTemp) 'Add each word to the sLine array
Next
For siCount1 = sLine.max DownTo 0 'Loop from the last in the sLine array to 0
sReverse &= sLine[siCount1] & " " 'Fill sReverse with words reversed, adding a space
Next
sOutput &= Trim(sReverse) & gb.NewLine 'Add the reversed words to sOutput and add a newline
sReverse = "" 'Clear sReverse
sLine.Clear 'Clear sLine array
Next
 
Print sOutput 'Print the output
 
End</lang>
Output:
<pre>
------------ Fire And Ice ----------
 
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.
 
... last paragraph elided ...
 
----------------------- Robert Frost
</pre>
 
=={{header|Go}}==
Anonymous user