Reverse words in a string: Difference between revisions

no edit summary
(Added XPL0 example.)
No edit summary
Line 3,931:
 
... last paragraph elided ...
 
----------------------- Robert Frost
</pre>
 
=={{header|Vlang}}==
<lang vlang>fn main() {
mut n := [
"---------- Ice and Fire ------------",
" ",
"fire, in end will world the say Some",
"ice. in say Some ",
"desire of tasted I've what From ",
"fire. favor who those with hold I ",
" ",
"... elided paragraph last ... ",
" ",
"Frost Robert -----------------------",
]
for i, s in n {
mut t := s.fields() // tokenize
// reverse
last := t.len - 1
for j, k in t[..t.len/2] {
t[j], t[last-j] = t[last-j], k
}
n[i] = t.join(" ")
}
// display result
for t in n {
println(t)
}
}</lang>
{{out}}
<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
338

edits