一、UrlEncode
- function URLEncode(const msg: String): String;
- var
- I : Integer;
- begin
- Result := '';
- for I := 1 to Length(msg) do begin
- if msg[I] = ' ' then
- Result := Result + '+'
- else if msg[I] in ['a'..'z', 'A'..'Z', '0'..'9'] then
- Result := Result + msg[I]
- else
- Result := Result + '%' + IntToHex(ord(msg[I]), 2);
- end;
- ShowMessage(result);
- end;
二、UrlDecode
- function urlDecode(url: string): string;
- var i, s, g: Integer;
- begin
- Result :='';
- for i := 1 to Length(url) do
- begin
- if url[i] = '%' then
- begin
- s := StrtoInt('$' + url[i + 1]) * 16;
- g := StrtoInt('$' + url[i + 2]);
- Result := Result + Chr(s + g);
- end
- 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
- Result := Result + url[i];
- end;
- ShowMessage(Result);
- end;
转载于:https://blog.51cto.com/amcto111/1180763