Reverse words in a string: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 366:
 
----------------------- Robert Frost</pre>
 
 
=={{header|AutoHotkey}}==
Line 539 ⟶ 538:
 
----------------------- Robert Frost</pre>
 
 
=={{header|Bracmat}}==
Line 636 ⟶ 634:
}</lang>
Output is the same as everyone else's.
 
=={{header|C sharp|C#}}==
<lang csharp>using System;
 
public class ReverseWordsInString
{
public static void Main(string[] args)
{
string text = @"
---------- 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 -----------------------
";
 
foreach (string line in text.Split(Environment.NewLine)) {
//Splits on any whitespace, not just spaces
string[] words = line.Split(default(char[]), StringSplitOptions.RemoveEmptyEntries);
Array.Reverse(words);
WriteLine(string.Join(" ", words));
}
}
}</lang>
 
=={{header|C++}}==
Line 744 ⟶ 771:
}
</lang>
 
=={{header|C sharp|C#}}==
<lang csharp>using System;
 
public class ReverseWordsInString
{
public static void Main(string[] args)
{
string text = @"
---------- 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 -----------------------
";
 
foreach (string line in text.Split(Environment.NewLine)) {
//Splits on any whitespace, not just spaces
string[] words = line.Split(default(char[]), StringSplitOptions.RemoveEmptyEntries);
Array.Reverse(words);
WriteLine(string.Join(" ", words));
}
}
}</lang>
 
=={{header|Clojure}}==
Line 1,302 ⟶ 1,300:
println[join[" ", reverse[split[%r/\s+/, line]]]]
</lang>
 
=={{header|Gema}}==
<lang gema>\L<G> <U>=@{$2} $1</lang>
 
=={{header|Gambas}}==
Line 1,357 ⟶ 1,352:
----------------------- Robert Frost
</pre>
 
=={{header|Gema}}==
<lang gema>\L<G> <U>=@{$2} $1</lang>
 
=={{header|Go}}==
Line 1,830 ⟶ 1,828:
end repeat
put txtrev</lang>
 
 
=={{header|LiveScript}}==
Line 1,960 ⟶ 1,957:
 
----------------------- Robert Frost</pre>
 
 
=={{header|Mathematica}}==
Line 2,476 ⟶ 2,472:
Frost Robert -----------------------
</lang>
 
=={{header|Perl 6}}==
We'll read input from stdin
<lang perl6>say ~.words.reverse for lines</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</pre>
 
=={{header|Phix}}==
Line 2,523 ⟶ 2,504:
----------------------- Robert Frost
</pre>
 
=={{header|PHP}}==
<lang php>
<?php
function strInv ($string) {
 
$str_inv = '' ;
 
for ($i=0,$s=count($string);$i<$s;$i++){
$str_inv .= implode(' ',array_reverse(explode(' ',$string[$i])));
$str_inv .= '<br>';
}
 
return $str_inv;
 
}
$string[] = "---------- Ice and Fire ------------";
$string[] = "";
$string[] = "fire, in end will world the say Some";
$string[] = "ice. in say Some";
$string[] = "desire of tasted I've what From";
$string[] = "fire. favor who those with hold I";
$string[] = "";
$string[] = "... elided paragraph last ...";
$string[] = "";
$string[] = "Frost Robert ----------------------- ";
 
 
echo strInv($string);</lang>
'''Output''':
 
<lang Shell>------------ 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</lang>
 
=={{header|PicoLisp}}==
Line 2,532 ⟶ 2,556:
{{Out}}
Same as anybody else.
 
=={{header|Pike}}==
<lang Pike>string story = #"---------- 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 -----------------------";
 
foreach(story/"\n", string line)
write("%s\n", reverse(line/" ")*" ");
</lang>
 
=={{header|PL/I}}==
Line 2,658 ⟶ 2,698:
Frost Robert ----------------------- ---> ----------------------- Robert Frost
</pre>
 
=={{header|PHP}}==
<lang php>
<?php
function strInv ($string) {
 
$str_inv = '' ;
 
for ($i=0,$s=count($string);$i<$s;$i++){
$str_inv .= implode(' ',array_reverse(explode(' ',$string[$i])));
$str_inv .= '<br>';
}
 
return $str_inv;
 
}
$string[] = "---------- Ice and Fire ------------";
$string[] = "";
$string[] = "fire, in end will world the say Some";
$string[] = "ice. in say Some";
$string[] = "desire of tasted I've what From";
$string[] = "fire. favor who those with hold I";
$string[] = "";
$string[] = "... elided paragraph last ...";
$string[] = "";
$string[] = "Frost Robert ----------------------- ";
 
 
echo strInv($string);</lang>
'''Output''':
 
<lang Shell>------------ 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</lang>
 
=={{header|Pike}}==
<lang Pike>string story = #"---------- 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 -----------------------";
 
foreach(story/"\n", string line)
write("%s\n", reverse(line/" ")*" ");
</lang>
 
=={{header|Python}}==
Line 2,825 ⟶ 2,806:
(loop (read-line poem-port))))))
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
We'll read input from stdin
<lang perl6>say ~.words.reverse for lines</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</pre>
 
=={{header|Red}}==
<lang Red>Red []
Line 2,842 ⟶ 2,840:
]
</lang>
 
=={{header|REXX}}==
===natural order===
Line 2,953 ⟶ 2,952:
 
Output the same as everyone else's.
 
 
=={{header|Run BASIC}}==
Line 3,014 ⟶ 3,012:
.join("\n")); // Concatenate lines into String
}</lang>
 
 
=={{header|S-lang}}==
10,327

edits