獲取各種編碼(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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM