中国开发网: 论坛: 程序员情感CBD: 贴子 437261
hmaik
delphi下的解决办法
function HTMLDecodeEx(const AStr: String): Widestring; //处理格式转换
var
Sp, Cp, Tp: PChar;
Rp:PWideString;
S: String;
I, Code: Integer;
begin
SetLength(Result, Length(AStr));
Sp := PChar(AStr);
Rp := PWideString(Result);
Cp := Sp;
try
while Sp^ <> #0 do
begin
case Sp^ of
'&': begin
Cp := Sp;
Inc(Sp);
case Sp^ of
'a': if AnsiStrPos(Sp, 'amp;') = Sp then { do not localize }
begin
Inc(Sp,3);
PInteger(Rp)^ := Integer('&');
end;
'l',
'g': if (AnsiStrPos(Sp, 'lt;') = Sp) or (AnsiStrPos(Sp, 'gt;') = Sp) then { do not localize }
begin
Cp := Sp;
Inc(Sp, 2);
while (Sp^ <> ';') and (Sp^ <> #0) do
Inc(Sp);
if Cp^ = 'l' then
PInteger(Rp)^ := Integer('<')
else
PInteger(Rp)^ := Integer('>');
end;
'q': if AnsiStrPos(Sp, 'quot;') = Sp then { do not localize }
begin
Inc(Sp,4);
PInteger(Rp)^ := Integer('"');
end;
'#': begin
Tp := Sp;
Inc(Tp);
while (Sp^ <> ';') and (Sp^ <> #0) do
Inc(Sp);
SetString(S, Tp, Sp - Tp);
Val(S, I, Code);
PInteger(Rp)^ := I;
end;
else
begin
result:='';
exit;
end;
end;
end
else ;
PInteger(Rp)^ := Integer(Sp^);
end;
Inc(PByte(Rp),2);
Inc(Sp);
end;
SetLength(Result, PChar(Rp)-PChar(Result));
except
result:='';
end;
end;

原文地址:http://none.blog.com.cn/archives/2006/1755293.shtml

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录