一、UrlEncode

 
  
  1. function URLEncode(const msg: String): String; 
  2. var 
  3.    I : Integer
  4. begin 
  5.    Result := ''
  6.    for I := 1 to Length(msg) do begin 
  7.        if msg[I] = ' ' then 
  8.            Result := Result + '+' 
  9.        else if msg[I] in ['a'..'z''A'..'Z''0'..'9'then 
  10.            Result := Result + msg[I] 
  11.        else 
  12.            Result := Result + '%' + IntToHex(ord(msg[I]), 2); 
  13.    end;  
  14.   ShowMessage(result); 
  15. end

 二、UrlDecode


 
  
  1. function urlDecode(url: string): string; 
  2. var i, s, g: Integer
  3. begin 
  4.   Result :=''
  5.  
  6.   for i := 1 to Length(url) do 
  7.   begin 
  8.  
  9.     if url[i] = '%' then 
  10.     begin 
  11.       s := StrtoInt('$' + url[i + 1]) * 16; 
  12.       g := StrtoInt('$' + url[i + 2]); 
  13.  
  14.       Result := Result + Chr(s + g); 
  15.     end 
  16.     else if not (((url[i - 1] = '%'and (url[i + 1] <> '%')) or ((url[i - 2] = '%'and (url[i - 1] <> '%'and (url[i + 1] = '%')) or ((url[i - 2] = '%'and (url[i - 1] <> '%'and (url[i + 1] <> '%'))) then 
  17.       Result := Result + url[i]; 
  18.  
  19.   end
  20.   ShowMessage(Result); 
  21. end