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 ...
随机推荐
- [转载]Axure RP 7.0下载地址及安装说明
Axure RP是产品经理必备的原型制作工具,因为很多同学是新手,在这里整理一下axure7.0的下载.安装和汉化流程,希望能够帮到大家. Axure RP是美国Axure Software Solu ...
- 【SoapUI、Postman、WebServiceStudio、Jmeter】接口测试工具结合测试webservice接口(发送XML格式参数)
目录: SoapUI测试webservice接口,发送XML格式参数 Postman测试webservice接口,发送XML格式参数 WebServiceStudio.exe测试webservice接 ...
- 8148 8168 中移植live55 出现except rtsp 中途莫名的断流
在解码中,接了浙江宇视的ipc相机,解码一般就挂了,vlc 也是中途断流.费解? vlc异常信息如下: packetizer_h264 warning: waiting for SPS/PPS pac ...
- mysql海量数据条件删除
1. 问题描述:现在存在两个表,具体表结构及记录数如下所示: mysql> desc user_mapping; +------------+------------------+------+ ...
- redis-windows和linux下安装
Window 下安装 下载地址:https://github.com/dmajkic/redis/downloads. 下载到的Redis支持32bit和64bit.根据自己实际情况选择,将64bit ...
- iptables的例子1
练习1:实现主机防火墙 设置主机防火墙策略为DROP: iptables -t filter -P INPUT DROP iptables -t filter -P OUTPUT DROP i ...
- apache .htaccess实现301重定向
<IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On #301定向 RewriteCond %{HTTP_HO ...
- thinkphp5, 模板继承、模板布局
---------------------------------------------------------------------------------------------------- ...
- [ZJOI2006]三色二叉树
[ZJOI2006]三色二叉树 BZOJ luogu 分3种颜色讨论转移一下 #include<bits/stdc++.h> using namespace std; const int ...
- (3)mac下"-bash: mysql: command not found"解决方案
针对 mysql: command not found 输入命令 $ ln -s /usr/local/mysql/bin/mysql /usr/bin 假如你人品不好,被打脸了,提示你权限不够: l ...