Anonymous user
Reverse words in a string: Difference between revisions
→{{header|MAXScript}}
Line 1,907:
----------------------- Robert Frost</pre>
=={{header|
<lang maxscript>
-- MAXScript : Reverse words in a string : N.H. 2019
testStr = {'---------- Ice and Fire ------------' ; ...▼
--
(
text = stringstream "---------- Ice and Fire ------------\n\nfire, in end will world the say Some\nice. in say Some\ndesire of tasted I've what From\nfire. favor who those with hold I\n\n... elided paragraph last ...\n\nFrost Robert -----------------------\n"
clearListener()
seek text 0
while eof text == false do
(
nextLine = (readLine text)
if nextLine == "" then
(
print ""
continue
) -- end of if
revLine = ""
eachWord = filterString nextLine " "
for k = eachWord.count to 1 by -1 do
(
revLine = revLine + eachWord[k]
-- Only add space between words not at the end of line
if k != 1 then revLine = revLine + " "
) -- end of for k
print revLine
) -- end of while eof
end</lang>▼
)
{{out}}
To MAXScript Listener:
""
"Some say the world will end in
"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|Modula-2}}==
|