如何检查 2 个数字是否具有相同的数字 PowerShell?

How can I check if a 2 numbers have the same digits PowerShell?

我想比较两个 int,如果它们包含相同的数字,则输出 true,例如:

$a=1260
$b=2106

然后因为它们都包含: 0126 它输出 true 如何做到这一点? 如果可以用最少的行数

这是一种技巧:

$null -eq (Compare-Object -ReferenceObject ([char[]][String]1260) -DifferenceObject ([char[]][String]2601))

returnstrue还是false,取决于数字是否相同。

这是另一个有点长的解决方案:

( $a.ToString().ToCharArray() | ForEach-Object { $c = $true } { if ( $b.ToString() -notmatch $_.ToString() ) { $c = $false } } { $c } ) -and ( $b.ToString().ToCharArray() | ForEach-Object { $c = $true } { if ( $a.ToString() -notmatch $_.ToString() ) { $c = $false } } { $c } )

这会将 int 作为数组进行比较,因此需要 运行 双向。