StrReverse


Definition: Returns a string in which the character order of a specified string is reversed.

 

How many times have you said to yourself, “Gosh, if only there was a way for me to reverse the character order of a specified string”? That’s what we thought.

 

Shockingly, Windows PowerShell has no equivalent to VBScript’s StrReversefunction; fortunately, though, we found at least one way to achieve the same effect. The following set of commands (which we won’t bother explaining in any detail) assigns the value Scripting Guysto the variable $a, then uses a For Next loop to reverse the order of the characters in the string:

 

$a = "Scripting Guys"
for ($ i= $ a.length- 1; $ i- ge0; $ i--) {$b = $b + ($ a.substring ($i,1))}

 

When you run this command and then echo back the value of $b you should get the following:

 

syuG gnitpircS

 

Note. Believe it or not, that’s what you’re supposedto get back!