Discussion:
Extracting parameters from an URL ?
(too old to reply)
R2D2
2008-06-29 11:31:29 UTC
Permalink
Hi,

I need to parse a MS URL similar to this :
search:query=seattle&crumb=location:C%3A%5CMyFolder

(see http://msdn.microsoft.com/en-us/library/cc144083(VS.85).aspx)

I'm interested in reading the value of the QUERY parameter. What Indy
component/Windows API should I use ? TIdURI seems to be only able to
encode an URI, and in my case I need to extract a parameter in an URI.

Thanks.
API
2008-06-29 16:06:40 UTC
Permalink
Post by R2D2
search:query=seattle&crumb=location:C%3A%5CMyFolder
function HtmlParamsToString( s: string
): string;
var
hexstr: string;
orig: string;
i: integer;
p: integer;
begin
if pos('+',s)>0 then s:=
stringreplace( s, '+', ' ',
[rfreplaceall] );
p:= pos('%', s);
while p>0 do
begin
p:= pos('%', s);
if p>0 then
begin
hexstr:= copy( s, p, 3 );
orig:= hexstr;
hexstr[1]:= '$';
try
i:= strtoint( hexstr );
s:= stringreplace( s, orig,
char(i), [rfreplaceall]);
except
p:= -1;
end;
end;
end;
result:= s;
end;

I think that IdUrl would do something
similar. In this unit there's function
called URLDecode which does almost the
same (except + is not space).
R2D2
2008-06-29 17:43:58 UTC
Permalink
Hi,
function HtmlParamsToString( s: string ): string;
Thanks. But in my case, I need also to search for the start of the
parameter (query=) and extract the string. Not much complicated, I can
use Pos()/Copy(), but I expected I could use something like
TIdURI.GetParamFromQueryString(TheUrl, TheParameter)... but that does
not exists :-) I'll need to write my own code.

Continue reading on narkive:
Loading...