Standard URL encode function?

后端 未结 13 1845
轻奢々
轻奢々 2020-11-30 05:33

Is there a Delphi equivalent of this .net\'s method:

Url.UrlEncode()

Note
I haven\'t worked with Delphi for several years now. As I

13条回答
  •  遥遥无期
    2020-11-30 06:05

    I made myself this function to encode everything except really safe characters. Especially I had problems with +. Be aware that you can not encode the whole URL with this function but you need to encdoe the parts that you want to have no special meaning, typically the values of the variables.

    function MyEncodeUrl(source:string):string;
     var i:integer;
     begin
       result := '';
       for i := 1 to length(source) do
           if not (source[i] in ['A'..'Z','a'..'z','0','1'..'9','-','_','~','.']) then result := result + '%'+inttohex(ord(source[i]),2) else result := result + source[i];
     end;
    

提交回复
热议问题