不知道为什么在以下字符串替换中强制转换为 int 在 Powershell 中失败:
PS D:\> $b = "\x26"
PS D:\> $b -replace '\\x([0-9a-fA-F]{2})', [char][int]'0x$1'
Cannot convert value "0x$1" to type "System.Int32". Error: "Could not find any recognizable digits."
At line:1 char:1
+ $b -replace '\\x([0-9a-fA-F]{2})', [char][int]'0x$1'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvalidCastFromStringToInteger
替换本身工作正常:
PS D:\> [char][int]($b -replace '\\x([0-9a-fA-F]{2})', '0x$1')
&