Standard URL encode function?

后端 未结 13 1878
轻奢々
轻奢々 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 05:54

    Update 2018: the code shown below seems to be outdated. see Remy's comment.

    class function TIdURI.ParamsEncode(const ASrc: string): string;
    var
      i: Integer;
    const
      UnsafeChars = '*#%<> []';  {do not localize}
    begin
      Result := '';    {Do not Localize}
      for i := 1 to Length(ASrc) do
      begin
        if CharIsInSet(ASrc, i, UnsafeChars) or (not CharIsInSet(ASrc, i, CharRange(#33,#128))) then begin {do not localize}
          Result := Result + '%' + IntToHex(Ord(ASrc[i]), 2);  {do not localize}
        end else begin
          Result := Result + ASrc[i];
        end;
      end;
    end;
    

    From Indy.


    Anyway Indy is not working properly so YOU NEED TO SEE THIS ARTICLE:
    http://marc.durdin.net/2012/07/indy-tiduri-pathencode-urlencode-and-paramsencode-and-more/

提交回复
热议问题