【问题标题】:Combine two Bytes to WideChar将两个字节合并为 WideChar
【发布时间】:2012-12-16 18:06:11
【问题描述】:

是否可以将两个Bytes 合并到WideChar,如果可以,那么如何?
例如,二进制中的字母“ē”是00010011 = 1900000001 = 1,或275 一起。

var
  WChar: WideChar;
begin
  WChar := WideChar(275); // Result is "ē"


var
  B1, B2: Byte;
  WChar: WideChar;
begin
  B1 := 19;
  B2 := 1;
  WChar := CombineBytesToWideChar(B1, B2); // ???

如何在 Delphi 中从两个字节中获取WideChar

【问题讨论】:

    标签: delphi delphi-7 unicode-string widechar multibyte-functions


    【解决方案1】:
    WChar := WideChar(MakeWord(B1, B2));
    

    【讨论】:

    • 啊,我忘了 MakeWord,很好 :)
    【解决方案2】:

    你应该能够创建一个类型并强制转换:

    type
      DoubleByte = packed record
        B1: Byte;
        B2: Byte;
      end;
    
    var
      DB: DoubleByte;
      WC: WideChar;
    begin
      DB.B1 := 19;
      DB.B2 := 1;
    
      WC = WideChar(DB);
    end;
    

    如果转换失败,您可以改用 Move() 并简单地复制内存。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-10
      • 2016-11-15
      • 1970-01-01
      • 2011-02-23
      • 2013-09-30
      相关资源
      最近更新 更多