引用 iduri uese idURI a:='a b c'; url:='http://abc.com/abc.php?p='+TIdURI.ParamsEncode(a);
很容易,看俺写的函数 function EnCode(Code: string): string; var I: Integer; Hex: string; begin for I := 1 to Length(Code) do case Code[i] of ' ': Result := Result + '+'; 'A'..'Z', 'a'..'z', '*', '@', '.', '_', '-', '0'..'9', '$', '!', '''', '(', ')': Result := Result + Code[i]; else begin Hex := IntToHex(ord(Code[i]), 2); if Length(Hex) = 2 then Result := Result + '%' + Hex else Result := Result + '%0' + hex; end; end; end;
上面那是从D7里找出来的,好象对中文操作有问题。 小改了一下 function EnCode(ACode: string): string; var I: Integer; Hex: string; Code: AnsiString; begin Code := AnsiString(ACode); for I := 1 to Length(Code) do case Code[i] of ' ': Result := Result + '+'; 'A'..'Z', 'a'..'z', '*', '@', '.', '_', '-', '0'..'9', '$', '!', '''', '(', ')': Result := Result + Code[i]; else begin Hex := IntToHex(ord(Code[i]), 2); if Length(Hex) = 2 then Result := Result + '%' + Hex else Result := Result + '%0' + hex; end; end; end;
a b c ,123,98yujsdf!@##^%%^&--中文123 -----------------》 a+b+c+%2C123%2C98yujsdf!@%23%23%5E%25%25%5E%26--%D6%D0%CE%C4123
uese idURI
a:='a b c';
url:='http://abc.com/abc.php?p='+TIdURI.ParamsEncode(a);
function EnCode(Code: string): string;
var
I: Integer;
Hex: string;
begin
for I := 1 to Length(Code) do
case Code[i] of
' ': Result := Result + '+';
'A'..'Z', 'a'..'z', '*', '@', '.', '_', '-',
'0'..'9', '$', '!', '''', '(', ')':
Result := Result + Code[i];
else
begin
Hex := IntToHex(ord(Code[i]), 2);
if Length(Hex) = 2 then
Result := Result + '%' + Hex
else
Result := Result + '%0' + hex;
end;
end;
end;
小改了一下
function EnCode(ACode: string): string;
var
I: Integer;
Hex: string;
Code: AnsiString;
begin
Code := AnsiString(ACode);
for I := 1 to Length(Code) do
case Code[i] of
' ': Result := Result + '+';
'A'..'Z', 'a'..'z', '*', '@', '.', '_', '-',
'0'..'9', '$', '!', '''', '(', ')':
Result := Result + Code[i];
else
begin
Hex := IntToHex(ord(Code[i]), 2);
if Length(Hex) = 2 then
Result := Result + '%' + Hex
else
Result := Result + '%0' + hex;
end;
end;
end;
-----------------》
a+b+c+%2C123%2C98yujsdf!@%23%23%5E%25%25%5E%26--%D6%D0%CE%C4123