2、如果不是ASNI编码格式,如何改成ASNI格式?分不够可以再加呀。

解决方案 »

  1.   

    以二进制方式打开,如果是unicode/utf-8,前几个字节是特别的标志
    utf/unicode到ansi,有专门的函数:以UTF8Decode查帮助,就能得到一整套了
      

  2.   

    也可以用判断文本文件的方式进行。
       function GetTextType(const FileName: string): String;
       var
         w: Word;
         b: Byte;
       begin
         with TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone) do
           try
             Read(w,2);
             w:=WordLoHiExchange(w);//因为是以Word数据类型读取,故高低字节互换
             if w = TextFormatFlag[tfUnicode] then
               Result := 'tfUnicode'
             else if w = TextFormatFlag[tfUnicodeBigEndian] then
               Result:= 'tfUnicodeBigEndian'
             else if w = TextFormatFlag[tfUtf8] then
               Result := 'tfUtf8'
             else
               Result := 'tfANSI';
           finally
             Free;
           end;
       end;