UTF-8 delphi 函数
unit util_utf8;
interface
uses Windows;
type
UTF8String = AnsiString;
function AnsiToWide(const S: AnsiString): WideString;
function WideToUTF8(const WS: WideString): UTF8String;
function AnsiToUTF8(const S: AnsiString): UTF8String;
function UTF8ToWide(const US: UTF8String): WideString;
function WideToAnsi(const WS: WideString): AnsiString;
function UTF8ToAnsi(const S: UTF8String): AnsiString;
implementation
function AnsiToWide(const S: AnsiString): WideString;
var
len: integer;
ws: WideString;
begin
Result:='';
if (Length(S) = ) then
exit;
len:=MultiByteToWideChar(CP_ACP, , PChar(s), -, nil, );
SetLength(ws, len);
MultiByteToWideChar(CP_ACP, , PChar(s), -, PWideChar(ws), len);
Result:=ws;
end;
function WideToUTF8(const WS: WideString): UTF8String;
var
len: integer;
us: UTF8String;
begin
Result:='';
if (Length(WS) = ) then
exit;
len:=WideCharToMultiByte(CP_UTF8, , PWideChar(WS), -, nil, , nil, nil);
SetLength(us, len);
WideCharToMultiByte(CP_UTF8, , PWideChar(WS), -, PChar(us), len, nil, nil);
Result:=us;
end;
function AnsiToUTF8(const S: AnsiString): UTF8String;
begin
Result:=WideToUTF8(AnsiToWide(S));
end;
function UTF8ToWide(const US: UTF8String): WideString;
var
len: integer;
ws: WideString;
begin
Result:='';
if (Length(US) = ) then
exit;
len:=MultiByteToWideChar(CP_UTF8, , PChar(US), -, nil, );
SetLength(ws, len);
MultiByteToWideChar(CP_UTF8, , PChar(US), -, PWideChar(ws), len);
Result:=ws;
end;
function WideToAnsi(const WS: WideString): AnsiString;
var
len: integer;
s: AnsiString;
begin
Result:='';
if (Length(WS) = ) then
exit;
len:=WideCharToMultiByte(CP_ACP, , PWideChar(WS), -, nil, , nil, nil);
SetLength(s, len);
WideCharToMultiByte(CP_ACP, , PWideChar(WS), -, PChar(s), len, nil, nil);
Result:=s;
end;
function UTF8ToAnsi(const S: UTF8String): AnsiString;
begin
Result:=WideToAnsi(UTF8ToWide(S));
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
IdHTTP1: TIdHTTP;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
util_utf8;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
strm: TStringStream;
begin
strm := TStringStream.Create('');
try
IdHTTP1.Get('http://gz.ganji.com/zpshichangyingxiao/', strm);
Memo1.Clear;
Memo1.Lines.Add(UTF8ToAnsi(strm.DataString));
finally
strm.Free;
end;
end;
end.
UTF-8 delphi 函数的更多相关文章
- 转:Delphi 函数大全
Delphi 函数大全 - xiucaiyao的专栏 - 博客频道 - CSDN.NEThttp://blog.csdn.net/xiucaiyao/article/details/4544039 名 ...
- cef3 获得js 返回值, 以及js 指挥delphi 函数的 总结参考
cef3 如何加载 本地html 文件. 请教老师[吐槽]常忘<run_fan@qq.com> 22:21:45@lazarus 下载cef3中的范例中就有 [吐槽]常忘< ...
- Delphi 函数指针(三大好处:灵活,委托的本质,回调机制),还可把函数指针当参数传入
首先学习: 指向非对象(一般的)函数/过程的函数指针 Pascal 中的过程类型与C语言中的函数指针相似,为了统一说法,以下称函数指针.函数指针的声明只需要参数列表:如果是函数,再加个返回值.例如声明 ...
- Delphi函数的out、var等关键字的作用,和使用场景
问题描述 Delphi函数的out.var等关键字的作用,和使用场景 Delphi函数的out.var等关键字的作用,和使用场景,我知道var是作为传值调用,但是像out这个关键字又是什么作用呢? 解 ...
- delphi函数大全
delphi函数大全Abort 函数 引起放弃的意外处理Abs 函数 绝对值函数AddExitProc ...
- delphi 函数isiconic 函数 判断窗口是否最小化
http://blog.sina.com.cn/s/blog_66357ab901012t2h.html delphi 函数isiconic 函数 判断窗口是否最小化 (2012-05-26 22:0 ...
- Delphi函数的返回值(注意这里与C/C++等语言有差异)
在C/C++等语言中,函数执行到 return 部分之后,将立即停止函数的执行,并返回值 但是在Delphi中不同 函数中,执行到result时,并不同于比如 C/C++ 中的 return,跳出函数 ...
- Delphi函数参数传递 默认参数(传值)、var(穿址)、out(输出)、const(常数)四类
Delphi的参数可以分为:默认参数(传值).var(传址).out(输出).const(常数)四类 可以对比C/C++的相关知识,类比学习. 1.默认参数是传值,不会被改变,例子 function ...
- Delphi函数指针
参考:http://blog.chinaunix.net/uid-91034-id-2009700.html http://blog.csdn.net/procedure1984/article/de ...
- Delphi函数翻译成VC要注意句柄指针传递(传递Handle的时候,必须加上一个指针引用,才能消除编译错误)
Delphi里做了魔法变化,每个变量名称本身就是指针,因为不怎么需要指针语法.我也不知道是不是因为这个原因引起的Delphi与VC对句柄的不同处理. 这是Delphi的强行关机函数,好用,调用方式:W ...
随机推荐
- iOS 获取LaunchImage启动图
iOS开发中,LaunchImage图片会根据手机机型的不同,自动匹配对应的图片,而我们如果想要拿到对应的图片,无法直接通过图片的名字获取该启动图,而需要通过以下方式 + (NSString *)ge ...
- 分析Memcached客户端如何把缓存数据分布到多个服务器上
Memcached客户端可以设多个memcached服务器,它是如何把数据分发到各个服务器上,而使各个服务器负载平衡的呢? 可以看看.net版中的客户端中的源码,就可以知道 先看代码: 1 /// ...
- mapreduce学习资料
http://blog.csdn.net/tianjun2012/article/category/6794531 http://blog.csdn.net/tianjun2012/article/d ...
- Error in as.POSIXlt.character(x, tz, ...) :
> sqlFetch(channel,"user")Error in as.POSIXlt.character(x, tz, ...) : character strin ...
- 为什么使用JSP?
JSP程序与CGI程序有着相似的功能,但和CGI程序相比,JSP程序有如下优势: 性能更加优越,因为JSP可以直接在HTML网页中动态嵌入元素而不需要单独引用CGI文件. 服务器调用的是已经编译好的J ...
- VMWare虚拟机下为Ubuntu 12.04.2配置静态IP(NAT方式)
http://www.cnblogs.com/objectorl/archive/2012/09/27/vmware-ubuntu-nat-static-ip-settings.html 参考以上方式 ...
- C#数组 多个集合和数组的操作(合并,去重,拆分,判断)
http://www.cnblogs.com/liguanghui/archive/2011/11/09/2242309.html http://www.cnblogs.com/dreamszx/ar ...
- 解决xcode5升级后,Undefined symbols for architecture arm64:问题
The issue is that the cocoapods have not been built for arm64 architecture yet thus they cannot be l ...
- Bag of mice(概率DP)
Bag of mice CodeForces - 148D The dragon and the princess are arguing about what to do on the New Y ...
- Hadoop伪分布式环境快速搭建
Hadoop分支 Apache Cloudera Hortonworks 本文是采用Cloudera分支的hadoop. 下载cdh-5.3.6 版本 下载地址:http://archive.clou ...