built-in reverse

反转字符串
反转字符串 在 PowerShell 中
function ReverseString([string] $String) {
    $charArray = $String.ToCharArray()
    [Array]::Reverse($charArray)
    -join $charArray
}

First, we turn the string into an array of chars. Then, we pass the char array into the static method Reverse of the class Array from .NET. Finally, we use -join to concatenate this char array back into one single string.

Array.Reverse method.

2026年09月23日 · 觉得有用?