示例:测试转码
转码:测试转码
function uni2ascii(html: string): string;
var
i, p, len: integer;
gbc, ttxt: string;
begin
p := pos('&#', html);
while (p <> 0) do
begin
i := p + 2;
len := length(html);
ttxt := '';
while (html[i] in ['0'..'9']) do
begin
ttxt := ttxt + html[i];
inc(i);
if i > len then
break;
end;
delete(html, p, i - p + 1);
if trim(ttxt) <> '' then
begin
gbc := widechar(strtoint(ttxt));
insert(gbc, html, p);
end;
p := pos('&#', html);
end;
p := pos('&#', html);
while (p <> 0) do
begin
i := p + 6;
len := length(html);
ttxt := '';
while (html[i] in ['0'..'9']) do
begin
ttxt := ttxt + html[i];
inc(i);
if i > len then
break;
end;
delete(html, p, i - p + 1);
gbc := widechar(strtoint(ttxt));
insert(gbc, html, p);
p := pos('&#', html);
end;
p := pos('<', html);
while (p <> 0) do
begin
delete(html, p, 4);
insert('<', html, p);
p := pos('<', html);
end;
p := pos('>', html);
while (p <> 0) do
begin
delete(html, p, 4);
insert('>', html, p);
p := pos('>', html);
end;
result := html;
end;