【问题标题】:Assign Unicode Literals to PowerShell Hash Table将 Unicode 文字分配给 PowerShell 哈希表
【发布时间】:2023-03-30 09:30:01
【问题描述】:

已经很晚了,今晚我已经完成了 - 有人可以帮我解决这个问题吗?我是否需要做一些额外的工作才能将这些 Unicode 字符串分配为文字?

首次尝试创建双编码和所需键值对的哈希表:

[string] $double_encoded_values = @{
"€"   = "€";
"‚"   = "‚";
"Æ’"    = "ƒ";
"„"   = "„";
"…"   = "…";
"â€"    = "†";
"‡"   = "‡";
"ˆ"    = "ˆ";
"‰"   = "‰";
"Å"     = "Š";
"‹"   = "‹";
"Å’"    = "Œ";
"Ž"    = "Ž";
"‘"   = "‘";
"’"   = "’";
"“"   = "“";
"â€"    = "”";
"•"   = "•";
"–"   = "–";
"—"   = "—";
"Ëœ"    = "˜" ;
"â„¢"   = "™";
"Å¡"    = "š";
"›"   = "›";
"Å“"    = "œ";
"ž"    = "ž";
"Ÿ"    = "Ÿ";
"¡"    = "¡";
"¢"    = "¢";
"£"    = "£";
"¤"    = "¤";
"Â¥"    = "¥";
"¦"    = "¦";
"§"    = "§";
"¨"    = "¨";
"©"    = "©";
"ª"    = "ª";
"«"    = "«";
"¬"    = "¬";
"®"    = "®";
"¯"    = "¯";
"°"    = "°";
"±"    = "±";
"²"    = "²";
"³"    = "³";
"´"    = "´";
"µ"    = "µ";
"¶"    = "¶";
"·"    = "·";
"¸"    = "¸";
"¹"    = "¹";
"º"    = "º";
"»"    = "»";
"¼"    = "¼";
"½"    = "½";
"¾"    = "¾";
} # $double_encoded_values

我的版本:

PS C:\Windows\system32> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1     

收到错误:

At line:20 char:12
    + "–"   = "–";
    +            ~
    Missing '=' operator after key in hash literal.
    At line:20 char:12
    + "–"   = "–";
    +            ~
    The hash literal was incomplete.
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingEqualsInHashLiteral

参考:http://www.i18nqa.com/debug/utf8-debug.html

【问题讨论】:

    标签: powershell unicode encoding unicode-literals


    【解决方案1】:

    PowerShell 将– 中的 视为双引号,从而有效地转义了"–" 中的关闭"

    使用单引号避免 PowerShell 尝试解析键名和值:

    @{
        '–' = '-'
    }
    

    【讨论】:

      猜你喜欢
      • 2013-07-19
      • 1970-01-01
      • 1970-01-01
      • 2011-07-20
      • 2012-01-09
      • 1970-01-01
      • 2018-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多