header image

Reverse a string

Posted by: | November 29, 2018 Comments Off on Reverse a string |

I sort of brushed over it on my last post but this is how you reverse a string.


function get-reversestring {
param (

$ca = $teststring.ToCharArray()


-join $ca


Take the input string and turn it into an array of chars. Use the reverse static method of the array class to reverse the array. Other useful array methods can be found in the documentation – https://docs.microsoft.com/en-us/dotnet/api/system.array?redirectedfrom=MSDN&view=netframework-4.7.2

-Join is used to stitch the reversed char array back into a string.

under: PowerShell

Comments are closed.