又有什么编码了? 就是把它用ASCII码来表示且前面加个%号罢了
编码:
procedure TForm2.Button1Click(Sender: TObject);
var
I: Integer;
S: string;
begin
S := Edit1.Text;
Edit2.Clear;
for I := 1 to Length(S) do
begin
Edit2.Text := Edit2.Text + '%' + IntToHex(Ord(S), 2);
end;
end;
解码?:
procedure TForm2.Button2Click(Sender: TObject);
function GetSubStr(S: string; Index: Integer; Separator: string = ','): string;
var
I, P: Integer;
begin
if Index < 1 then Exit;
if (S <> '') and (S[Length(S)] <> Separator) then
S := S + Separator;
for I := 1 to Index - 1 do
begin
P := System.Pos(Separator, S);
Delete(S, 1, P);
end;
Result := Trim(Copy(S, 1, System.Pos(Separator, S) - 1));
end;
function FStrToInt(S: Char): Integer;
begin
case S of
'0': Result := 0;
'1': Result := 1;
'2': Result := 2;
'3': Result := 3;
'4': Result := 4;
'5': Result := 5;
'6': Result := 6;
'7': Result := 7;
'8': Result := 8;
'9': Result := 9;
'A', 'a': Result := 10;
'B', 'b': Result := 11;
'C', 'c': Result := 12;
'D', 'd': Result := 13;
'E', 'e': Result := 14;
'F', 'f': Result := 15;
else
Result := 0;
end;
end;
var
I: Integer;
S: string;
TmpS: array of Char;
begin
I := 0;
repeat
Inc(I);
S := GetSubStr(Copy(Edit2.Text, 2, MAXINT), I, '%');
if Length(S) = 2 then
begin
SetLength(TmpS, Length(TmpS) + 1);
TmpS[High(TmpS)] := Chr(FStrToInt(S[1]) * 16 + FStrToInt(S[2]));
end;
until S = '';
Edit1.Text := Trim(PChar(TmpS));
end;