use*_*182 8 powershell encode utf-8
我想在PowerShell中将字符串编码为UTF8.
这是我试过的:
$consumer_key ="xvz1evFS4wEEPTGEFPHBog"
$enc_consumer_key = System.Text.UTF8Encoding($consumer_key)
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
System.Text.UTF8Encoding无法识别为cmdlet的名称
小智 16
试试这个:
$enc = [System.Text.Encoding]::UTF8
$consumerkey ="xvz1evFS4wEEPTGEFPHBog"
$encconsumerkey= $enc.GetBytes($consumerkey)
Run Code Online (Sandbox Code Playgroud)
小智 15
编码/解码:
\n\n$enc = [System.Text.Encoding]::UTF8.GetBytes("\xc3\xa2")\n# 195 162\n[System.Text.Encoding]::UTF8.GetString($enc)\n# \xc3\xa2\n[System.Text.Encoding]::ASCII.GetString($enc)\n# ??\n[System.Text.Encoding]::Default.GetString($enc) # Windows-1252\n# \xc3\x83\xc2\xa2\nRun Code Online (Sandbox Code Playgroud)\n\n这是我搜索的最好的问题,它引导我找到上述在 PowerShell 中进行文本编码/解码字符的解决方案。就我而言,我试图调试格式错误的 UTF8 字符。希望它对将来的人有所帮助。
\n\n-检查BOM
\n如果您只想将字符串写入文件:
$consumer_key ="xvz1evFS4wEEPTGEFPHBog"
$consumer_key | Out-File c:\path\utf8file.txt -Encoding UTF8
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45582 次 |
| 最近记录: |