DELPHI XE8安卓下汉字转GB2312 URLENCODE代码


本文整理自网络,侵删。

 Delphi XE8安卓下汉字转Gb2312 urlencode代码

在Android下汉字转GB2312 urlencode时候,如果使用下边代码:

用Edit2.Text :=Tnetencoding.url.EncodeBytesToString( Tencoding.GetEncoding(936).getbytes('提交'));//会提示错误No mapping for the Unicode character exists in the target multi-byte code page.

用Edit2.Text :=httpencode('提交'); urlencode结果为  %E6%8F%90%E4%BA%A4 ,此为UTF8转换结果

用Edit2.Text :=Tnetencoding.URL.Encode('提交'); urlencode结果同样为%E6%8F%90%E4%BA%A4

那么问题来了,怎么在Android显示GB2312的转换结果%cc%e1%bd%bb呢?

 

function MyUrlEncode(const input: string): string; // 汉字转Gb2312 urlencode
var
  S: string;
  Stream: TStringStream;
  B: Byte;
begin
  Result := '';
  S := '';
  try
    Stream := TStringStream.Create(input, TEncoding.GetEncoding(936));
    for B in Stream.Bytes do
      S := Format('%s%%%.2x', [S, B]);
  finally
    Stream.Free;
  end;
  Result := S;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit1.Text := '提交';
  Edit2.Text := MyUrlEncode(Edit1.Text); // 结果  %cc%e1%bd%bb
end;

相关阅读 >>

Delphi iddecodermime 对图像编码base64解码成图像文件

Delphi远程注入dll方法

Delphi 调用dll运行正常,退出时弹出错误解决办法

Delphi firdac 对 sqlite 数字, int64也会被截断,会出现负数情况处理

Delphi实现分割文本文件的小程序

Delphi 查询当前目录下文件名是否存在

Delphi 读写文本文件

Delphi xe7开发的获取网页中字符串的编码是否是utf8

Delphi�⒆执�传入到windows目前窗口cursor所在位置

Delphi win10系统已管理员的权限运行应用程序

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...