Reverse text line

Problem

Reverse a line of text without the use of Array’s Reverse method, Array indices, Array notation, pipelines or loop statements.

Solution

1
2
$str = '!ereh saw yorliK'
-join (New-Object RegEx ., RightToLeft).Matches($str)

Set the RightToLeft option to an “all-characters-in-a-line” matching Regular Expression and pass the line of text to its Matches method. This will return all the characters in the line from the end to the start of the line. Then, use the Join operator to return the reversed text.


Winner: Rob Campbell

Share on: