delphi TEncoding
#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的更多相关文章
- c++builder 字节 编码 转换大全 String TBytes byte
System.SysUtils System::DynamicArray<System::WideChar> TCharArray System::TArray__1<System: ...
- Delphi XE6 原生解析json
Delphi XE5带了system.json单元,原生提供了json支持类.下面是解析json用法说明: 最简单的JSON大致像这样 { "date":"周二(今天, ...
- delphi中webbrowser的用法
WebBrowser1.GoHome; //到浏览器默认主页 WebBrowser1.Refresh; //刷新 WebBrowser1.GoBack; //后退 WebBrowser1.GoForw ...
- 使用delphi+intraweb进行微信开发5—准备实现微信API,先从获取AccessToken开始
在前4讲中我们已经使iw开发的应用成功和微信进行了对接,再接下来的章节中我们开始逐一尝试和实现微信的各个API,开始前先来点准备工作 首先需要明确的是,微信的API都是通过https调用实现的,分为p ...
- 使用delphi+intraweb进行微信开发4—微信消息加解密
示例代码已经放出!请移步使用delphi+intraweb进行微信开发1~4代码示例进行下载,虽为示例代码但是是从我项目中移出来的,封装很完备适于自行扩展和修改. 在上一讲当中我做了个简单的微信文本消 ...
- DELPHI支付宝支付代码
真实业务场景的考虑 按照支付宝或者微信支付的开发手册的说法,一个标准的客户端接入支付业务模型应该是这样的,我忽略时序图,只用文字描述: 用户登录客户端,选择商品,然后点击客户端支付. 客户端收集商品信 ...
- Android实例-Delphi开发蓝牙官方实例解析(XE10+小米2+小米5)
相关资料:1.http://blog.csdn.net/laorenshen/article/details/411498032.http://www.cnblogs.com/findumars/p/ ...
- Delphi WebBrowser控件的使用(大全 good)
Delphi WebBrowser控件的使用 WebBrowser控件属性:1.Application 如果该对象有效,则返回掌管WebBrowser控件的应用程序实现的自动化对象(IDis ...
- Delphi TWebBrowser
Delphi WebBrowser控件的使用 WebBrowser控件属性:1.Application 如果该对象有效,则返回掌管WebBrowser控件的应用程序实现的自动化对象(IDis ...
随机推荐
- Aizu-2200-floyd+dp
Mr. Rito Post Office 你是一个为远程邮局邮局工作的程序员.你住的地区由几个岛屿组成.每个岛屿都有一个或多个港口城镇.除此之外,还有其他城镇和村庄.为了从一个岛到另一个岛,你必须使用 ...
- UVA-11248 Frequency Hopping (最大流+最小割)
题目大意:给一张网络,问是否存在一条恰为C的流.若不存在,那是否存在一条弧,使得改动这条弧的容量后能恰有为C的流? 题目分析:先找出最大流,如果最大流不比C小,那么一定存在一条恰为C的流.否则,找出最 ...
- css中的f弹性盒子模型的应用案例
案例1: <!doctype html> <html> <head> <meta charset="utf-8"> <meta ...
- hrbust 1621 迷宫问题II 广搜
题目链接:http://acm.hrbust.edu.cn/vj/index.php?/vj/index.php?c=&c=contest-contest&cid=134#proble ...
- c/c++指针常见错误
一 #include <bits/stdc++.h> using namespace std; void f(char *str) { char *s = str; str[] = ' / ...
- 记录下返回list给前端 遇到 $ref":"$.data.*** 问题
1.通过对象返回给前端,对象里面有三个list 2.一个父list 2个子list 子list中的对象 是通过for循环父list按照某个条件放进去的 3.直接放进去会出现 $ref":& ...
- Sub-process /usr/bin/dpkg returned an error code (1)解决方法
在ubuntu下使用apt-get install 安装资源的时候,总是会遇到Sub-process /usr/bin/dpkg returned an error code (1) 错了, 跟安装软 ...
- 在jenkins和sonar中集成jacoco(四)--在sonar中集成jacoco
首先要得到之前的单元测试和集成测试的覆盖率文件,还有对应的class文件以及单元测试的覆盖率报告,材料准备齐全之后,使用如下命令: build.xml 1 2 3 4 5 6 7 8 9 10 11 ...
- Eclipse中使用Maven,报错“$MAVEN_HOME”
1.今天在用eclipse时,执行maven命令,报错,如图"$MAVEN_HOME" 解决方案: 1.点击 windows---preferences,打开preferences ...
- I.MX6 Android 5 root
/********************************************************************************* * I.MX6 Android 5 ...