Delphi中文本文件Utf-8和Ansi转换

const
  IS_TEXT_UNICODE_ASCII16 = $1;
  IS_TEXT_UNICODE_REVERSE_ASCII16 = $10;
  IS_TEXT_UNICODE_STATISTICS = $2;
  IS_TEXT_UNICODE_REVERSE_STATISTICS = $20;
  IS_TEXT_UNICODE_CONTROLS = $4;
  IS_TEXT_UNICODE_REVERSE_CONTROLS = $40;
  IS_TEXT_UNICODE_SIGNATURE = $8;
  IS_TEXT_UNICODE_REVERSE_SIGNATURE = $80;
  IS_TEXT_UNICODE_ILLEGAL_CHARS = $100;
  IS_TEXT_UNICODE_ODD_LENGTH = $200;
  IS_TEXT_UNICODE_DBCS_LEADBYTE = $400;
  IS_TEXT_UNICODE_NULL_BYTES = $1000;
  IS_TEXT_UNICODE_UNICODE_MASK = $F;
  IS_TEXT_UNICODE_REVERSE_MASK = $F0;
  IS_TEXT_UNICODE_NOT_UNICODE_MASK = $F00;
  IS_TEXT_UNICODE_NOT_ASCII_MASK = $F000;

function DecordUtf8: String;
var
  MyOpt : Integer;
  Text: String;
begin
  Text := 'WWWWWWWWWWWW'; //可以为从文件中读出来的字符
  MyOpt := IS_TEXT_UNICODE_UNICODE_MASK;
  if IsTextUnicode(PChar(Text), length(Text), @MyOpt) then
    Text:= Utf8Decode(Text);
  Result := Text;
end;

posted @ 2010-09-03 16:52  Max Woods  阅读(2944)  评论(0编辑  收藏  举报