#include <tchar.h>
#include <memory> //For STL auto_ptr class
//--------------------------------------------------------------------------- #pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
// Sample to convert a file of any encoding to UTF8
TEncoding *LEncoding = NULL;
std::auto_ptr<TFileStream> LFileStream(new TFileStream("..\\Sample.txt", fmOpenRead)); // Read file into buffer.
TBytes myBytes;
std::auto_ptr<TBytesStream> myBytesStream(new TBytesStream(myBytes));
myBytesStream->CopyFrom(LFileStream.get(), LFileStream->Size); // Identify encoding and convert buffer to UTF8.
int LOffset = TEncoding::GetBufferEncoding(myBytesStream->Bytes, LEncoding);
if (LOffset == )
return ; // Unknown encoding; do not convert.
myBytes = TEncoding::Convert(LEncoding, TEncoding::UTF8,
myBytesStream->Bytes,
LOffset, myBytesStream->Size-LOffset);
// Create output file.
std::auto_ptr<TFileStream> DestFileStream(new TFileStream("..\\SampleUTF8.txt", fmCreate)); // Write UTF8 byte-order mark and buffer to output file.
TBytes LByteOrderMark;
LByteOrderMark = TEncoding::UTF8->GetPreamble(); // Grab preamble and write to destination.
DestFileStream->Write(&LByteOrderMark[], LByteOrderMark.Length); // Write converted buffer.
DestFileStream->Write(&myBytes[], myBytes.Length);
return ;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// You may need to change this path to suit your environment.
String Path = "../../"+Edit1->Text;
Memo1->Lines->LoadFromFile(Path);
if (Memo1->Lines->Encoding != NULL)
Edit2->Text = Memo1->Lines->Encoding->EncodingName;
Memo1->ScrollBars = ssVertical;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// You may need to change this path to suit your environment.
TEncoding *myEncoding;
String Path = "../../"+Edit1->Text;
myEncoding = TEncoding::Default;
if (Edit2->Text == "ASCII") myEncoding = TEncoding::ASCII;
if (Edit2->Text == "BigEndianUnicode") myEncoding = TEncoding::BigEndianUnicode;
if (Edit2->Text == "Default") myEncoding = TEncoding::Default;
if (Edit2->Text == "Unicode") myEncoding = TEncoding::Unicode;
// Do not use UTF7 for this. It does not have a BOM, and so the encoding cannot be detected on a load.
// if (Edit2->Text == "UTF7") then myEncoding = TEncoding::UTF7;
if (Edit2->Text == "UTF8") myEncoding = TEncoding::UTF8;
Memo1->Lines->SaveToFile(Path, myEncoding);
}

Default是936   (ANSI/OEM - 简体中文 GBK)

Memo1->Lines->SaveToFile(FileName,TEncoding::UTF8);

Memo1->Lines->WriteBOM=false; //utf8  BOM

gb2312,它的代码页是936

uses System.SysUtils

Str:=  TEncoding.Default.GetString(finallyByte);

delphi TEncoding的更多相关文章

  1. c++builder 字节 编码 转换大全 String TBytes byte

    System.SysUtils System::DynamicArray<System::WideChar> TCharArray System::TArray__1<System: ...

  2. Delphi XE6 原生解析json

    Delphi XE5带了system.json单元,原生提供了json支持类.下面是解析json用法说明: 最简单的JSON大致像这样 { "date":"周二(今天, ...

  3. delphi中webbrowser的用法

    WebBrowser1.GoHome; //到浏览器默认主页 WebBrowser1.Refresh; //刷新 WebBrowser1.GoBack; //后退 WebBrowser1.GoForw ...

  4. 使用delphi+intraweb进行微信开发5—准备实现微信API,先从获取AccessToken开始

    在前4讲中我们已经使iw开发的应用成功和微信进行了对接,再接下来的章节中我们开始逐一尝试和实现微信的各个API,开始前先来点准备工作 首先需要明确的是,微信的API都是通过https调用实现的,分为p ...

  5. 使用delphi+intraweb进行微信开发4—微信消息加解密

    示例代码已经放出!请移步使用delphi+intraweb进行微信开发1~4代码示例进行下载,虽为示例代码但是是从我项目中移出来的,封装很完备适于自行扩展和修改. 在上一讲当中我做了个简单的微信文本消 ...

  6. DELPHI支付宝支付代码

    真实业务场景的考虑 按照支付宝或者微信支付的开发手册的说法,一个标准的客户端接入支付业务模型应该是这样的,我忽略时序图,只用文字描述: 用户登录客户端,选择商品,然后点击客户端支付. 客户端收集商品信 ...

  7. Android实例-Delphi开发蓝牙官方实例解析(XE10+小米2+小米5)

    相关资料:1.http://blog.csdn.net/laorenshen/article/details/411498032.http://www.cnblogs.com/findumars/p/ ...

  8. Delphi WebBrowser控件的使用(大全 good)

    Delphi WebBrowser控件的使用 WebBrowser控件属性:1.Application      如果该对象有效,则返回掌管WebBrowser控件的应用程序实现的自动化对象(IDis ...

  9. Delphi TWebBrowser

    Delphi WebBrowser控件的使用 WebBrowser控件属性:1.Application      如果该对象有效,则返回掌管WebBrowser控件的应用程序实现的自动化对象(IDis ...

随机推荐

  1. bzoj-1009-dp+kmp处理转移矩阵幂

    1009: [HNOI2008]GT考试 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 4723  Solved: 2940[Submit][Statu ...

  2. 获取div的高度

    1.获取div的文档总高度(必须DOM操作): var scrollHeight=document.getElementById("inner").scrollHeight; // ...

  3. qt Cannot connect creator comm socket /tmp/qt_temp.S26613/stub-socket: No such

    Tool->Options->Environment->General 将terminal改为 xterm -e

  4. iptables Configuration

    iptables usage: Add Rules: iptables -I INPUT -p tcp --dport -j ACCEPT iptables -I INPUT -p tcp --dpo ...

  5. web 常用富文本编辑器

    1. 百度家的 UEditor  官网地址http://ueditor.baidu.com/website/;在线演示地址:http://ueditor.baidu.com/website/onlin ...

  6. 根据马甲、应用商店、统计每天的注册量,要求可以根据选择马甲和app,马甲和appstrore和user_login不同表问题

    这个马甲属于一个表,appStore另一张表,用户登录表,主要操作的就是这三个表. 我这里的马甲和app的id都与用户登录表中的channel对应,在channel存放的是majiaId + “|” ...

  7. 490 - Rotating Sentences

     Rotating Sentences  In ``Rotating Sentences,'' you are asked to rotate a series of input sentences ...

  8. python functiontools 模块

    一个内置的模块.  作用是实现了更多的功能, 同时形式上显得很简洁.    虽然在使用很方便, 但其中的原理还是很难复杂的. ------------------------------------- ...

  9. gqlgen golang graphql server 基本试用

    gqlgen golang 的graphql server 具体代码参考https://github.com/rongfengliang/gqlgen-demo 特点 模型优先 类型安全 代码生成 安 ...

  10. Rotor envoy control plane 简单试用

    rotor 基于golang 的envoy xds 服务,支持多种集成方式: k8s consul aws dc/os demo试用docker 以及consul 进行环境运行 下载demo 可以试用 ...