Mega Code Archive

 
Categories / Delphi / Strings
 

Format a string for cgi requests

function FormatStringforCGI(str: string): string; var i: integer; begin for i := 1 to Length(str) do begin if str[i] in ['a'..'z', 'A'..'Z', '0', '1'..'9'] then Result := Result + Str[i] else if Str[i] = ' ' then Result := Result + '+' else Result := Result + '%' + IntToHex(Byte(Str[i]), 2); end; end;