Format中两个%代表一个% ShowMessage(Format('%%%.2x%%%.2x%%%.2x%%%.2x', [Ord('鞋子'[1]), Ord('鞋子'[2]), Ord('鞋子'[3]), Ord('鞋子'[4])]));//参考如下代码 function UrlEncode(mUrl: string): string; var I: Integer; begin Result := ''; for I := 1 to Length(mUrl) do begin case mUrl[I] of #33..#126: Result := Result + mUrl[I]; else Result := Result + '%' + IntToHex(Ord(mUrl[I]), 2); end; end; end; { UrlEncode }procedure TForm1.Button1Click(Sender: TObject); begin Caption := UrlEncode('鞋子') end;
inttohex(ord('鞋子'[2]),1), inttohex(ord('鞋子'[3]),1),
inttohex(ord('鞋子'[4]),1)]))
format('%s', [inttohex(ord('鞋子'[2]),1)])+'%'+
format('%s', [inttohex(ord('鞋子'[3]),1)])+'%'+
format('%s', [inttohex(ord('鞋子'[4]),1)])+'%')补充一下 其实和1 楼完全是一样的
'%'+format('%s', [inttohex(ord('鞋子'[1]),1)])+
'%'+format('%s', [inttohex(ord('鞋子'[2]),1)])+
'%'+format('%s', [inttohex(ord('鞋子'[3]),1)])+
'%'+format('%s', [inttohex(ord('鞋子'[4]),1)]))
ShowMessage(Format('%%%.2x%%%.2x%%%.2x%%%.2x', [Ord('鞋子'[1]), Ord('鞋子'[2]), Ord('鞋子'[3]), Ord('鞋子'[4])]));//参考如下代码
function UrlEncode(mUrl: string): string;
var
I: Integer;
begin
Result := '';
for I := 1 to Length(mUrl) do
begin
case mUrl[I] of
#33..#126: Result := Result + mUrl[I];
else Result := Result + '%' + IntToHex(Ord(mUrl[I]), 2);
end;
end;
end; { UrlEncode }procedure TForm1.Button1Click(Sender: TObject);
begin
Caption := UrlEncode('鞋子')
end;