Började just programmera i Delphi (2 dagen på gång re'n), å funderade om man på något sätt kan "urldecoda" något som man har urlencodat med PHP och urlencoda text tillbaka oxå?
Tacksam för svar,
Jontto
2 svar · 207 visningar · startad av Jontto
Började just programmera i Delphi (2 dagen på gång re'n), å funderade om man på något sätt kan "urldecoda" något som man har urlencodat med PHP och urlencoda text tillbaka oxå?
Tacksam för svar,
Jontto
Testa dessa funktioner.
function URLDecode(ASrc: string): string;
var
i: integer;
ESC: string[2];
CharCode: integer;
begin
Result := '';
ASrc := StringReplace(ASrc, '+', ' ', [rfReplaceAll]); {do not localize}
i := 1;
while i <= Length(ASrc) do begin
if ASrc *<> '%' then begin {do not localize}
Result := Result + ASrc
*end else begin
Inc(i); // skip the % char
ESC := Copy(ASrc, i, 2); // Copy the escape code
Inc(i, 1); // Then skip it.
try
CharCode := StrToInt('$' + ESC); {do not localize}
if (CharCode > 0) and (CharCode < 256) then begin
Result := Result + Char(CharCode);
end;
except end;
end;
Inc(i);
end;
end;
function URLEncode(ASrc: string): string;
const
UnsafeChars = ['*', '#', '%', '<', '>', '+']; {do not localize}
var
i: Integer;
begin
Result := '';
for i := 1 to Length(ASrc) do begin
if ASrc = ' ' then begin {do not localize}
Result := Result + '+'; {do not localize}
end else if (ASrc in UnsafeChars) or (ASrc >= #$80) then begin
Result := Result + '%' + IntToHex(Ord(ASrc), 2); {do not localize}
end else begin
Result := Result + ASrc;
end;
end;
end;******
Hade varit trevligt om man använder kodtaggarna när man postar kod... :OO