Phrase reversals: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(→‎{{header|AppleScript}}: Added alternative code.)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 16:
* [[Reverse words in a string]]
<br><br>
 
=={{header|AutoHotkey}}==
<lang AutoHotKey>var =
(
Rosetta Code Phrase Reversal
)
 
array := strsplit(var, " ")
 
loop, % array.maxindex()
string .= array[array.maxindex() - A_index + 1] . " "
 
loop, % array.maxindex()
{
m := array[A_index]
array2 := strsplit(m, "")
Loop, % array2.maxindex()
string2 .= array2[array2.maxindex() - A_index + 1]
string2 .= " "
}
 
array := strsplit(string, " " )
 
loop, % array.maxindex()
{
m := array[A_index]
array3 := strsplit(m, "")
Loop, % array3.maxindex()
string3 .= array3[array3.maxindex() - A_index + 1]
string3 .= " "
}
 
MsgBox % var . "`n" . string3 . "`n" . String . "`n" . string2
ExitApp
 
esc::ExitApp</lang>
 
{{out}}
 
<pre>Rosetta Code Phrase Reversal
lasreveR esarhP edoC attesoR
Reversal Phrase Code Rosetta
attesoR edoC esarhP lasreveR
</pre>
 
=={{header|Ada}}==
Line 338 ⟶ 294:
attesor edoc esahp lasrever
reversal phase code rosetta"</pre>
 
=={{header|AutoHotkey}}==
<lang AutoHotKey>var =
(
Rosetta Code Phrase Reversal
)
 
array := strsplit(var, " ")
 
loop, % array.maxindex()
string .= array[array.maxindex() - A_index + 1] . " "
 
loop, % array.maxindex()
{
m := array[A_index]
array2 := strsplit(m, "")
Loop, % array2.maxindex()
string2 .= array2[array2.maxindex() - A_index + 1]
string2 .= " "
}
 
array := strsplit(string, " " )
 
loop, % array.maxindex()
{
m := array[A_index]
array3 := strsplit(m, "")
Loop, % array3.maxindex()
string3 .= array3[array3.maxindex() - A_index + 1]
string3 .= " "
}
 
MsgBox % var . "`n" . string3 . "`n" . String . "`n" . string2
ExitApp
 
esc::ExitApp</lang>
 
{{out}}
 
<pre>Rosetta Code Phrase Reversal
lasreveR esarhP edoC attesoR
Reversal Phrase Code Rosetta
attesoR edoC esarhP lasreveR
</pre>
 
=={{header|AWK}}==
Line 542:
Reversed order: "reversal phrase code rosetta"
</pre>
 
=={{header|C sharp}}==
 
<lang csharp>using System;
using System.Linq;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
//Reverse() is an extension method on IEnumerable<char>.
//The constructor takes a char[], so we have to call ToArray()
Func<string, string> reverse = s => new string(s.Reverse().ToArray());
 
string phrase = "rosetta code phrase reversal";
//Reverse the string
Console.WriteLine(reverse(phrase));
//Reverse each individual word in the string, maintaining original string order.
Console.WriteLine(string.Join(" ", phrase.Split(' ').Select(word => reverse(word))));
//Reverse the order of each word of the phrase, maintaining the order of characters in each word.
Console.WriteLine(string.Join(" ", phrase.Split(' ').Reverse()));
}
}
}</lang>
 
=={{header|C++}}==
Line 573 ⟶ 598:
Original word order reversed : reversal phrase code rosetta
</pre>
 
=={{header|C sharp}}==
 
<lang csharp>using System;
using System.Linq;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
//Reverse() is an extension method on IEnumerable<char>.
//The constructor takes a char[], so we have to call ToArray()
Func<string, string> reverse = s => new string(s.Reverse().ToArray());
 
string phrase = "rosetta code phrase reversal";
//Reverse the string
Console.WriteLine(reverse(phrase));
//Reverse each individual word in the string, maintaining original string order.
Console.WriteLine(string.Join(" ", phrase.Split(' ').Select(word => reverse(word))));
//Reverse the order of each word of the phrase, maintaining the order of characters in each word.
Console.WriteLine(string.Join(" ", phrase.Split(' ').Reverse()));
}
}
}</lang>
 
=={{header|Clojure}}==
Line 722:
"reversal phrase code rosetta"
</lang>
 
=={{header|Elena}}==
ELENA 4.x :
Line 1,463 ⟶ 1,464:
"attesor edoc esarhp lasrever"
"reversal phrase code rosetta"</pre>
 
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Line 1,567:
2. Each word reversed : attesor edoc esarhp lasrever
</pre>
 
=={{header|Perl 6}}==
<lang perl6>my $s = 'rosetta code phrase reversal';
 
put 'Input : ', $s;
put 'String reversed : ', $s.flip;
put 'Each word reversed : ', $s.words».flip;
put 'Word-order reversed : ', $s.words.reverse;</lang>
{{out}}
<pre>Input : rosetta code phrase reversal
String reversed : lasrever esarhp edoc attesor
Each word reversed : attesor edoc esarhp lasrever
Word-order reversed : reversal phrase code rosetta</pre>
 
=={{header|Phix}}==
Line 1,926 ⟶ 1,913:
attesor edoc esarhp lasrever
reversal phrase code rosetta</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>my $s = 'rosetta code phrase reversal';
 
put 'Input : ', $s;
put 'String reversed : ', $s.flip;
put 'Each word reversed : ', $s.words».flip;
put 'Word-order reversed : ', $s.words.reverse;</lang>
{{out}}
<pre>Input : rosetta code phrase reversal
String reversed : lasrever esarhp edoc attesor
Each word reversed : attesor edoc esarhp lasrever
Word-order reversed : reversal phrase code rosetta</pre>
 
=={{header|REXX}}==
Line 2,113 ⟶ 2,114:
attesor edoc esarhp lasrever
reversal phrase code rosetta</pre>
 
=={{header|Swift}}==
<lang swift>
10,327

edits