PowerShell中汉字转换为ASCII编码

Posted 恋恋风尘

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PowerShell中汉字转换为ASCII编码相关的知识,希望对你有一定的参考价值。

function asc($param) { 
$rtn = ‘‘
$list = $param -split ‘‘
foreach ($char in $list)
{
    if($char -ne ‘‘)
    {
       $rtn = $rtn + ("u" + ("{0:x}" -f [int]([char]$char)))
    }
}
return $rtn 
}

 

$source="u54ceu5466u4e0du9519u54e6"
$evaluator={
param($v)
[char][int]($v.Value.replace(‘u‘,‘0x‘))
}
[regex]::Replace($source,‘\u[0-9-a-f]{4}‘,$evaluator)

write-host "Press any key to continue..."

read-host

 

以上是关于PowerShell中汉字转换为ASCII编码的主要内容,如果未能解决你的问题,请参考以下文章