function HttpEncode(S:AnsiString):string;
var
P:^Byte;
I:Cardinal;
begin
Result:=\'\';
P:=@S[1];
Result:=Format(\'%%%x\',[Ord(P^)]);
for I := 1 to Length(S)-1 do
begin
Inc(P);
Result:=Format(\'%s%%%x\',[Result,Ord(P^)]);
end;
end;
function HttpDecode(str:AnsiString): string;
var
List: TStrings;
tmpStr: AnsiString;
i: Integer;
begin
List := TStringList.Create;
ExtractStrings([\'%\'], [\'%\'], PChar(str), List);
SetLength(tmpStr, List.Count);
for i := 0 to List.Count - 1 do
Byte(tmpStr[i+1]) := StrToInt(\'$\' + List[i]);
List.Free;
Result := Utf8Decode(tmpStr);
end;
procedure TuMain.btnStartClick(Sender: TObject);
var
i :integer;
s: string;
begin
s:=\'衣服\';
s:=HttpEncode(AnsiToUtf8(s));
showmessage(s); //显示 %E8%A1%A3%E6%9C%8D
s := HttpDecode(s);
showmessage(s);
end;