delphi获取各种编码的识别符  
官方Delphi 学习QQ群: 682628230(三千人)\n
频道

delphi获取各种编码的识别符


下面是常用编码的识别符, 在 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}

{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;


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.043147802352905 seconds