![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Извлечение имени файла из интернет-ссылки [D6, D7, WinXP]
KonstantinXaker(KX) © (2005-05-22 15:48:00)Здорово!
Есть ссылка " http://www.mota.ru/space/img/space_087.jpg"
Каким образом мне извлечь название самого рисунка "space_087.jpg" с помощью Delphi?
P.S.: И не обязательно рисунка, а также любых файлов!
Anatoly Podgoretsky (2005-05-30 23:52:00) [1]Мне лень, поскольку мне не нужно, а ему я предложил попробовать
False_Delirium (2005-05-30 23:31:00) [2]Anatoly Podgoretsky © (30.05.05 23:14) [28]
LastDelimiter и Copy ? Больше собственно ничего и нет в
ExtractFileName.
А поменять там первый параметр LastDelimiter.
Лень, наверное. :)
Anatoly Podgoretsky (2005-05-30 23:14:00) [3]KonstantinXaker(KX) (25.05.05 20:59) [4]
Утверждает что нет, слеши то другие.
False_Delirium (2005-05-30 23:04:00) [4]Alexander Panov © (30.05.05 22:57) [26]
Если все запросы такого вида, то подойдёт [3] :)
Если любого вида, то [16] :)
Alexander Panov (2005-05-30 22:57:00) [5]False_Delirium © (30.05.05 22:48) [24]
Дык тоже на [21] обрати внимание-)
just_me (2005-05-30 22:50:00) [6]var
URI: TidURI;
begin
URI := TidURI.Create(' http://www.mota.ru/space/img/space_087.jpg');
try
Label1.Caption := URI.Document;
finally
URI.Free;
end;
end;
False_Delirium (2005-05-30 22:48:00) [7]Alexander Panov © (30.05.05 22:40) [23]
Так а зачем нам файл в параметрах :)
Нам нужен file1.txt :)
Alexander Panov (2005-05-30 22:40:00) [8]False_Delirium © (30.05.05 22:37) [22]
ну так извлекаем и получаем file2.txt -)
False_Delirium (2005-05-30 22:37:00) [9]Alexander Panov © (30.05.05 22:23) [21]
www.delphimaster.ru/file1.txt?id=1116762539&n=4&u= http://www.delphimaster.ru/file2.txt
Alexander Panov (2005-05-30 22:23:00) [10]Anatoly Podgoretsky © (30.05.05 22:11) [20]
Анатолий, топик прочитай;)
Там тип ссылки вполне конкретный приведен-)
Anatoly Podgoretsky (2005-05-30 22:11:00) [11]http://www.delphimaster.ru
Alexander Panov (2005-05-30 21:49:00) [12]Самое простое - пройти в с конца строки до первого попавшегося слеша '/'.
False_Delirium (2005-05-30 20:52:00) [13]Pearled (30.05.05 13:55) [17]
Работает медленно и неправильно.. :)
как и
Antonn © (29.05.05 11:45) [15]
Pearled (2005-05-30 13:55:00) [14]function ExtractUrlFileName(URL: string): string;
var
i: integer;
begin
if pos('?',url)>0 then
delete(url,pos('?',url),1000);
result:= url;
for i:= length(url) downto 1 do
if url[i] = '/' then
begin
result:= copy(url,i+1,1000);
break;
end;
end;
False_Delirium (2005-05-29 15:18:00) [15]
function ExtractURLFileName(const Url : string ; const DetermFileByDot : Boolean = True) : string ;
Var
Idx : SmallInt ;
LimitIdx : SmallInt ;
DotFound : Boolean ;
begin
Result := '' ;
DotFound := not DetermFileByDot ;
LimitIdx := Pos(#63, Url) - 1;
if LimitIdx = -1 then
begin
LimitIdx := Length(Url) ;
end ;
if (Url[LimitIdx] <> #47) and (LimitIdx > 6) then
begin
Idx := LimitIdx ;
while Idx > 6 do
begin
Dec(Idx) ;
if Url[Idx] = #46 then
DotFound := True ;
if Url[Idx] = #47 then
break
end ;
if (Idx > 6) and DotFound and (Url[Idx - 1] <> #47) then
Result := copy(Url, Idx + 1, LimitIdx - Idx)
end
end ;
На корректность URL не проверяет и не самая быстрая.
Antonn (2005-05-29 11:45:00) [16]ух, видали мой велосипед?
:)
function Get_URL2filename(_URL:string):string;
var i,i_s:integer; _s:string; _b:boolean;
begin
i_s:=-1; _b:=false;
result:='';
for i:=1 to length(_url) do begin
if (_url[i]='.') then _b:=true;
if (_url[i]='/')and(_b) then
i_s:=i;
end;
if i_s<0 then exit;
_s:=copy(_url, i_s+1, length(_url)-i_s);
i_s:=pos('.',_s);
result:=(_s);
_s:=_s+' ';
for i:=i_s to length(_s) do
if pos(_s[i],'/=+"?|:#@'#39)>0 then begin
result:=trim(copy(_s, 1, i_s)+copy(_s, i_s+1, i-i_s-1));
exit;
end;
end;
Anatoly Podgoretsky (2005-05-29 10:01:00) [17]А с этой
http://www.delphimaster.ru
и с этой
http://www.delphimaster.ru/
или с этой
http://www.delphimaster.ru/file.txt?id=1116762539&n=4
а еще лучше с этой
http://www.delphimaster.ru/file1.txt?id=1116762539&n=4&u=http://www.delphimaster.ru/file2.txt
KonstantinXaker(KX) (2005-05-29 02:18:00) [18]Medved ©
Так что тебе нужно получить из этой ссылки?
forum.pl?id=1116762539&n=4
Если это, то пишешь следующее (было написано выше):
function ExtrFnm(const FileName: string): string;
var tmp:String;
begin
tmp:=FileName;
while pos('/',tmp)>0 do
delete(tmp,1,pos('/',tmp));
result:=tmp;
end;
edit2.Text:=ExtrFnm(edit1.Text);
Anatoly Podgoretsky (2005-05-27 22:08:00) [19]KonstantinXaker(KX) (27.05.05 22:02) [10]
Что же так, код рабочий, значит URL неверный?
Medved (2005-05-27 22:02:00) [20]Это была моя первая идея... но
А если ссылка как на эту страницу?
http://www.delphimaster.ru/cgi-bin/forum.pl?id=1116762539&n=4
или ещё сложнее???