【问题标题】:F# .Net portable subset Unicode issuesF# .Net 可移植子集 Unicode 问题
【发布时间】:2013-07-17 03:58:53
【问题描述】:

好的,我在 VS2012 中创建了一个 F# 可移植库项目,我有一些表示 Utf-32 编码字符的整数,例如:0x0001D538,这是一个双击 A。通常将其变成 Utf-16 代理项配对你会使用System.Char.ConvertFromUtf32(i),工作完成。但是,Microsoft 已经决定不将此方法包含在 .net 可移植子集中。 (它在必须运行完整 .net 的交互式窗口中运行良好)。那么,我应该怎么做才能从这些整数中得到我最喜欢的代理对呢?它们需要是整数,因为我对它们做了一些算术运算。等待下一个版本的出现是一个可行的选择。

【问题讨论】:

    标签: unicode f# portable-class-library


    【解决方案1】:

    这里是来自 Reflector 的 C# 的快速翻译。可以用吗?

    type System.Char with
      static member ConvertFromUtf32(utf32) =
        if utf32 < 0 || utf32 > 0x10ffff || (utf32 >= 0xd800 && utf32 <= 0xdfff) then
          invalidArg "utf32" "Out of range"
        elif utf32 < 0x10000 then 
          new String(char utf32, 1)
        else
          let utf32 = utf32 - 0x10000
          new String([| char ((utf32 / 0x400) + 0xd800); char ((utf32 % 0x400) + 0xdc00) |])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-01
      相关资源
      最近更新 更多