• 获取各种编码(Unicode,UTF8等)的识别符


    下面是常用编码的识别符, 在 Delphi(2009) 中如何获取呢?
    Unicode: FF FE; BigEndianUnicode: FE FF; UTF8: EF BB BF


    var
      bs: TBytes;
      b: Byte;
      str: string;
    begin
      {只有 Unicode、BigEndianUnicode、UTF8 编码有识别符}
      bs := TEncoding.Unicode.GetPreamble;
      str := '';
      for b in bs do str := Format('%s %x', [str, b]);
      ShowMessage(str); {FF FE}
    
      bs := TEncoding.BigEndianUnicode.GetPreamble;
      str := '';
      for b in bs do str := Format('%s %x', [str, b]);
      ShowMessage(str); {FE FF}
    
      bs := TEncoding.UTF8.GetPreamble;
      str := '';
      for b in bs do str := Format('%s %x', [str, b]);
      ShowMessage(str); {EF BB BF} 在判断时,需要加上#$  如:if HeaderStr = #$EF#$BB#$BF then 
    
      {ASCII、UTF7 和 Default(默认编码) 没有识别符}
      bs := TEncoding.ASCII.GetPreamble;
      str := '';
      for b in bs do str := Format('%s %x', [str, b]);
      ShowMessage(str); {无}
    
      bs := TEncoding.UTF7.GetPreamble;
      str := '';
      for b in bs do str := Format('%s %x', [str, b]);
      ShowMessage(str); {无}
    
      bs := TEncoding.Default.GetPreamble;
      str := '';
      for b in bs do str := Format('%s %x', [str, b]);
      ShowMessage(str); {无} 
    end;
  • 相关阅读:
    软件工程个人作业01
    个人冲刺——(五)
    个人冲刺——(四)
    个人冲刺——(三)
    个人冲刺——(二)
    个人冲刺——(一)
    单词统计
    第十周学习总结
    第九周学习总结
    用户模板场景分析
  • 原文地址:https://www.cnblogs.com/weijie-liu/p/10138316.html
Copyright © 2020-2023  润新知