Reverse words in a string: Difference between revisions

No edit summary
(→‎{{header|Elixir}}: here document)
Line 527:
 
=={{header|Elixir}}==
<lang elixir>defmodule RC do
defmodule RC do
def reverse_words(txt) do
txt |> String.split("\n") # split lines
Line 537 ⟶ 536:
|> Enum.join("\n") # rejoin lines
end
end</lang>
</lang>
Usage:
<lang elixir>txt = """
"---------- Ice and Fire ------------\n" <>
txt =
" \n" <>
"---------- Ice and Fire ------------\n" <>
"fire, in end will world the say Some\n" <>
" \n" <>
"ice. in say Some \n" <>
"fire, in end will world the say Some\n" <>
"desire of tasted I've what From \n" <>
"ice. in say Some \n" <>
"fire. favor who those with hold I \n" <>
"desire of tasted I've what From \n" <>
" \n" <>
"fire. favor who those with hold I \n" <>
... elided paragraph last ...
" \n" <>
"... elided paragraph last ... \n" <>
"Frost Robert -----------------------"
" \n" <>
"""
"Frost Robert -----------------------"
 
IO.puts RC.reverse_words(txt)</lang>
</lang>
 
=={{header|Gema}}==
Anonymous user