我用的D5,怎么没有AnsiToUtf8()函数?
这个函数的原代码是什么?
这个函数的原代码是什么?
解决方案 »
- 再散分,捎带一个问题
- 我要疯了,为什么不对啊?高手帮我看看啊。。。。数据库的统计
- 那里可以下载DELPHI2006
- 问题急!!
- 登陆窗口的问题
- 我想作一个小程序实现sql语法检查,和执行sql脚本。
- 我做一个程序是用做发邮件的,没有带验证的,每次发邮件的时候都要输入密码之类的东西,有点烦有没有什么方法去掉呀(我是用DELPHI与的)
- 急,怎样将C:\WINDOWS\Temporary Internet Files中的文件拷到另外的目录
- 如何直接读写USB软驱(for 98/2000/xp)!
- 怎样编写程序才可让一个TDBEdit是要用户必须输入的???
- delphi的tabsheet页头怎样响应鼠标双击事件?
- maskedit判断日期正确格式
function Utf8Encode(const WS: WideString): UTF8String;
var
L: Integer;
Temp: UTF8String;
function UnicodeToUtf8(Dest: PChar; MaxDestBytes: Cardinal; Source: PWideChar; SourceChars: Cardinal): Cardinal;
var
i, count: Cardinal;
c: Cardinal;
begin
Result := 0;
if Source = nil then Exit;
count := 0;
i := 0;
if Dest <> nil then
begin
while (i < SourceChars) and (count < MaxDestBytes) do
begin
c := Cardinal(Source[i]);
Inc(i);
if c <= $7F then
begin
Dest[count] := Char(c);
Inc(count);
end
else if c > $7FF then
begin
if count + 3 > MaxDestBytes then
break;
Dest[count] := Char($E0 or (c shr 12));
Dest[count+1] := Char($80 or ((c shr 6) and $3F));
Dest[count+2] := Char($80 or (c and $3F));
Inc(count,3);
end
else // $7F < Source[i] <= $7FF
begin
if count + 2 > MaxDestBytes then
break;
Dest[count] := Char($C0 or (c shr 6));
Dest[count+1] := Char($80 or (c and $3F));
Inc(count,2);
end;
end;
if count >= MaxDestBytes then count := MaxDestBytes-1;
Dest[count] := #0;
end
else
begin
while i < SourceChars do
begin
c := Integer(Source[i]);
Inc(i);
if c > $7F then
begin
if c > $7FF then
Inc(count);
Inc(count);
end;
Inc(count);
end;
end;
Result := count+1; // convert zero based index to byte count
end;
begin
Result := '';
if WS = '' then Exit;
SetLength(Temp, Length(WS) * 3); // SetLength includes space for null terminator L := UnicodeToUtf8(PChar(Temp), Length(Temp)+1, PWideChar(WS), Length(WS));
if L > 0 then
SetLength(Temp, L-1)
else
Temp := '';
Result := Temp;
end;
//
我把这个函数提出来了,看看你能用吗?
MultiByteToWideChar
WideCharToMultiByte