在delphi中怎样对字符串进行urlencode编码

2016-08-22 10:17:59来源:http://wesoho.blog.51cto.com/715082/215116作者:wesoho人点击


function URLencode(str:string):string;var i:integer; temp:string;begin for i:= 1 to length(str) do begin temp:=temp+'%'+inttohex(integer(str[i]),0); end; result:=temp;end;
function URLdecode(str:string):string;var temp:string; i:integer;begin setlength(temp,length(str) div 3); i:=1; while(i<length(str)) do begin temp[(i+2)div 3]:=char(strtoint('$'+str[i+1]+str[i+2])); inc(i,3); end; Result:=temp;end;

functionHTTPEncode(constAStr:string):string; const NoConversion=['A'..'Z','a'..'z','*','@','.','_','-']; var Sp,Rp:PChar; begin SetLength(Result,Length(AStr)*3); Sp:=PChar(AStr); Rp:=PChar(Result); whileSp^<>#0do begin ifSp^inNoConversionthen Rp^:=Sp^ elseifSp^=''then Rp^:='+' else begin FormatBuf(Rp^,3,'%%%.2x',6,[Ord(Sp^)]); Inc(Rp,2); end; Inc(Rp); Inc(Sp); end; SetLength(Result,Rp-PChar(Result)); end; procedureTForm1.Button1Click(Sender:TObject); begin Edit1.Text:=HTTPEncode(Edit1.Text); end;

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台