Reverse words in a string: Difference between revisions

no edit summary
(Reverse words in a string in BASIC256)
No edit summary
Line 1,472:
println[join[" ", reverse[split[%r/\s+/, line]]]]
</lang>
 
=={{header|FutureBasic}}==
<lang futurebasic>
include "NSLog.incl"
 
CFStringRef frostStr
CFArrayRef frostArr, tempArr
CFMutableStringRef mutStr
NSInteger i, count
 
frostStr = @"---------- Ice and Fire ------------\n¬
\n¬
fire, in end will world the say Some\n¬
ice. in say Some\n¬
desire of tasted I've what From\n¬
fire. favor who those with hold I\n¬
\n¬
… elided paragraph last …\n¬
\n¬
Frost Robert -----------------------\n"
 
frostArr = fn StringComponentsSeparatedByString( frostStr, @"\n" )
count = fn ArrayCount( frostArr )
mutStr = fn MutableStringWithCapacity( 0 )
 
for i = 0 to count - 1
tempArr = fn StringComponentsSeparatedByString( frostArr[i], @" " )
tempArr = fn EnumeratorAllObjects( fn ArrayReverseObjectEnumerator( tempArr ) )
MutableStringAppendString( mutStr, fn ArrayComponentsJoinedByString( tempArr, @" " ) )
MutableStringAppendString( mutStr, @"\n" )
next
 
NSLog( @"%@", mutStr )
 
HandleEvents
</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|Gambas}}==
715

edits