这是网页编码吧 用下面的 函数 转换成正常字符 function urlDecode(url: string): string; var i, s, g: Integer; begin Result :=''; for i := 1 to Length(url) do begin if url[i] = '%' then begin s := StrtoInt('$' + url[i + 1]) * 16; g := StrtoInt('$' + url[i + 2]); Result := Result + Chr(s + g); end else if url[i] = '+' then begin Result:=Result+' '; end else if not (((url[i - 1] = '%') and (url[i + 1] <> '%')) or ((url[i - 2] = '%') and (url[i - 1] <> '%') and (url[i + 1] = '%')) or ((url[i - 2] = '%') and (url[i - 1] <> '%') and (url[i + 1] <> '%'))) then Result := Result + url[i]; end; end;
转换成正常字符
function urlDecode(url: string): string;
var i, s, g: Integer;
begin
Result :='';
for i := 1 to Length(url) do
begin
if url[i] = '%' then
begin
s := StrtoInt('$' + url[i + 1]) * 16;
g := StrtoInt('$' + url[i + 2]);
Result := Result + Chr(s + g);
end
else if url[i] = '+' then
begin
Result:=Result+' ';
end
else if not (((url[i - 1] = '%') and (url[i + 1] <> '%')) or ((url[i - 2] = '%') and (url[i - 1] <> '%') and (url[i + 1] = '%')) or ((url[i - 2] = '%') and (url[i - 1] <> '%') and (url[i + 1] <> '%'))) then
Result := Result + url[i];
end;
end;
然后使用的时候
用S:=HTTPEncode('中国');
S的结果就是%D6%D0%B9%FA
edit1.Text:=UTF8Decode(urlDecode('%E5%81%9C%E7%95%99'));
结果是 停留
如果要反向
则 edit1.Text:=HTTPEncode(Utf8Encode('停留'));//结果 为%E5%81%9C%E7%95%99 可将 urlDecode 换成 HTTPDecode
如何编码已经给出 D7 测试成功
edit1.Text:=HTTPEncode(Utf8Encode('停留'));//结果 为%E5%81%9C%E7%95%99