最近用一些网络分析软件发现,自己在网页提交内容的时候,一些中文会被转换成%E6%98%AF%E4%B8%8D%E6%这种的一种方式提交到服务器,我想请问一下,如何将中文转换成这种乱码呢?有没有这样的代码,谢谢
解决方案 »
- Delphi使用MyDAC连接MySQL数据库报错?
- 如何从WINDOWS日志中获取WINDOWS启动、关闭的时间
- HI,在Delphi 中如何实现 SQL数据库分页浏览,实现 上一页,下一页的翻页功能呢?
- 怎么在delphi中调用IIS里的web Service
- adoquery的删除错误,请教!
- 200分!up的都有分,怎么下载这样的文件?
- 今天只想找地方散分!!
- outlook打不开,各位出点主意。
- 就这点分了。如何在DELPHI里面实现RPC呢?或者通过网络传递对象?
- 有关制作安装程序的问题?(并祝大家国庆快乐)
- 求教:如何在richedit中读取,某个txt文件中记录的几个数值?
- 关于合同的问题
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 + Char(s + g);
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; 就是一種將字符轉為十六進制的編碼,上段代碼翠前用過,不過對中文支持不好。你要考慮下如何將兩個字節合並成一個的問題。Result := Result + Char(s + g); // DELPHI2009的
如果DELPHI7
Result := Result + Chr(s + g);
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 + Char(s + g);
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;
这代码写的也太麻烦了吧,半天没看懂,最后才明白.倒不如用while循环更直观一些function urlDecode(url: string): string;
var i, s, g: Integer;
begin
Result :='';
i := 1; while (i <= Length(url)) do begin
if url[i] = '%' then begin
s := StrtoInt('$' + url[i + 1]) * 16;
g := StrtoInt('$' + url[i + 2]);
inc(i,2);
Result := Result + Chr(s + g);
end
else begin
Result := Result + url[i];
end;
inc(i);
end;
end;
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 + Char(s + g);
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; 这代码写的也太麻烦了吧,半天没看懂,最后才明白.倒不如用while循环更直观一些
function urlDecode(url: string): string;
var i, s, g: Integer;
begin
Result :='';
i := 1; while (i <= Length(url)) do begin
if url[i] = '%' then begin
s := StrtoInt('$' + url[i + 1]) * 16;
g := StrtoInt('$' + url[i + 2]);
inc(i,2);
Result := Result + Chr(s + g);
end
else begin
Result := Result + url[i];
end;
inc(i);
end;
end;
重新排一下版,可能会更好看一些.