[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Url To Filename

Posted on 2000-05-11
9
Medium Priority
?
308 Views
Last Modified: 2010-04-04
I need a way to take a full url, and get just the end filename into a string.

For Example, convert:
http://www.microsoft.com/windows/win2k/index.html

Into:
index.html

Thanks!
0
Comment
Question by:Psylord
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 3

Expert Comment

by:sburck
ID: 2800102
function GetFileNameFromURL(URL : string);
var
    i : integer;
begin
    if length(URL) = 0 then
    begin
        result := '';
        exit;
    end;
    i := length(URL);
    while ((i > 0) and (URL[i] <> '\')) do
        dec(i);
    if (URL[i] <> '\') then
        result := '';
    else
          if i = length(URL) then
               result := '';
          else
                result := Copy(URL,i+1,length(URL));
end;
0
 
LVL 3

Expert Comment

by:sburck
ID: 2800109
Whoops - make the first line
 
function GetFileNameFromURL(URL : string) :  string;

of course
0
 
LVL 3

Expert Comment

by:sburck
ID: 2800117
And, yet another obvious fix: reverse the slashes (use '/', not '\').  This is what happens when you're in a hurry to answer....
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Accepted Solution

by:
ITugay earned 40 total points
ID: 2800160
Why so difficult?

function ExtractURLFileName(aPath : string) : string;
var I : integer;
begin
   I:=length(aPath);
   while (I>0) and (aPath[I] <> '/') do dec(I);
   result:=Copy(aPath,I+1,length(aPath)-I);
end;
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2800205
And again

function ExtractURLFileName(aPath : string) : string;
begin
   result:=ExtractFileName(StringReplace(aPath,'/','\',[rfReplaceAll]));
end;
0
 
LVL 3

Expert Comment

by:sburck
ID: 2800217
If you pass an empty string to the accepted answer,you'll get an exception. However, no arguments with the second answer, which is a nice idea.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2800219
Psylord,
do not forget "uses ...,sysutils,..." in last sample.

Cheers,
Igor
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2800227
to sbruck,
did you try to pass empty string?
----
Igor
0
 
LVL 3

Expert Comment

by:sburck
ID: 2800263
Nope, and my apologies - I learned something new about the Copy function.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question