超级编码、解码问题? (50分)

  • 主题发起人 主题发起人 yninfo
  • 开始时间 开始时间
Y

yninfo

Unregistered / Unconfirmed
GUEST, unregistred user!
function URLEncode(const msg : String) : String;
var
I : Integer;
begin
Result := '';
for I := 1 to Length(msg) do begin
if msg = ' ' then
Result := Result + '+'
else if msg in ['a'..'z', 'A'..'Z', '0'..'9'] then
Result := Result + msg
else
Result := Result + '%' + IntToHex(ord(msg), 2);
end;
end;

function HexToInt(Tstr:string):longint; //十六进制转十进制
var i,Tlen :integer;
p1:array [0..1] of char;
begin
result:=0;
Tstr:=trim(Tstr);
tlen:=length(Tstr);
for i:=1 to tlen do
begin
StrPcopy(p1,copy(Tstr,i,1));
result:=result*16+Toint(p1[0]);
end
end;



function Toint(Tstr:char) :integer;
begin
if ord((tstr)) >=65 then result:=10+ord(Tstr)-65
else result:=ord(Tstr)-48;
end;

//URLDecode解码思路
function URLDecode(const msg : String) : String;
HexToInt( );
chr(184)+chr(240);


求ms word 中文.doc 文档 通过WEB方式编辑后另存到服务器端后的乱码的解码函数??
 
function UrlDecode(const EncodedStr: String): String;
var
I: Integer;
begin
Result := '';
if Length(EncodedStr) > 0 then
begin
I := 1;
while I <= Length(EncodedStr) do
begin
if EncodedStr = '%' then
begin
Result := Result + Chr(HexToInt(EncodedStr[I+1]
+ EncodedStr[I+2]));
I := Succ(Succ(I));
end
else if EncodedStr = '+' then
Result := Result + ' '
else
Result := Result + EncodedStr;

I := Succ(I);
end;
end;
end;

function HexToInt(HexStr: String): Int64;
var RetVar : Int64;
i : byte;
begin
HexStr := UpperCase(HexStr);
if HexStr[length(HexStr)] = 'H' then
Delete(HexStr,length(HexStr),1);
RetVar := 0;

for i := 1 to length(HexStr) do begin
RetVar := RetVar shl 4;
if HexStr in ['0'..'9'] then
RetVar := RetVar + (byte(HexStr) - 48)
else
if HexStr in ['A'..'F'] then
RetVar := RetVar + (byte(HexStr) - 55)
else begin
Retvar := 0;
break;
end;
end;

Result := RetVar;
end;
 
接受答案了.
 

Similar threads

I
回复
0
查看
684
import
I
I
回复
0
查看
814
import
I
I
回复
0
查看
574
import
I
后退
顶部