Friday, November 20, 2026
HomePowershellThe right way to reverse a String – SID-500.COM

The right way to reverse a String – SID-500.COM


PowerShell

On this publish, I’ll present the best way to reverse a string, i.e., the best way to change it from again to entrance. To spark some concepts on the best way to method this, I’ve offered just a few examples.
Get pleasure from exploring the chances!

# 1
$originalString = "Hiya, World!"
$reversedString = -join $originalString[-1..-($originalString.Length)]
Write-Host $reversedString

# 2
$string = 'Patrick'
-join $string.ToCharArray()[-1..-$string.Length]

# 3
-join 'Patrick'.ToChararray()[-1..-'Patrick'.Length]

# 4
$namen = 'Patrick','Herbert','Hans','Peter'
foreach ($identify in $namen) {
    -join $identify.ToCharArray()[-1..-$name.Length]
}

# 5 # Out of Subject: Reverse Numbers
(1..100)[-1..-100] # oder 100..1
100..1

Hope this was useful.

Unknown's avatar

Printed by Patrick Gruenauer

Microsoft MVP on PowerShell & Microsoft 365, IT-Coach, IT-Guide, MCSE: Cloud Platform and Infrastructure, Cisco Licensed Academy Teacher.

Previous articleOh No, Overflow!
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments