Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Sep 23, 2018 8:30 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: SOLVED: How to get the file name from an URL?
PostPosted: Fri Dec 28, 2012 8:32 am 
Offline

Joined: Fri Oct 16, 2009 12:05 pm
Posts: 23
Location: Denmark
How do you get the file name from an URL like:

"http://www.somesite.com/a_folder/another_folder/and_maybe_a_lot_of_other_folders/60272_800_800_0_0_0_0_2.jpg"

I know I could start from the end of the URL with Right(URL, n) and then increase n in a "For/Next loop" until the character is a "/".

But can it be done smarter?


Last edited by ojan on Fri Dec 28, 2012 2:32 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: How to get the file name from an URL?
PostPosted: Fri Dec 28, 2012 10:43 am 
Offline

Joined: Wed May 20, 2009 4:43 pm
Posts: 958
Look at the Split command.

_________________
RB 2009r4 Windows XP


Top
 Profile  
Reply with quote  
 Post subject: Re: How to get the file name from an URL?
PostPosted: Fri Dec 28, 2012 11:25 am 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
dim parts() as string = url.Split( "/" )
dim fileName as string = parts( parts.Ubound )

or
dim fileName as string = url.NthField( "/", url.CountFields( "/" ) )

or
dim rx as new RegEx
rx.SearchPattern = "[^/]+$"

dim match as RegExMatch = rx.Search( url )
dim fileName as string
if match <> nil then fileName = match.SubexpressionString( 0 )

It makes no practical difference, but I'd expect the first version to be faster, and easier to debug.

_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.


Top
 Profile  
Reply with quote  
 Post subject: Re: How to get the file name from an URL?
PostPosted: Fri Dec 28, 2012 2:31 pm 
Offline

Joined: Fri Oct 16, 2009 12:05 pm
Posts: 23
Location: Denmark
Thank you, markwalsh and ktekinay

You just gave me an aha experience.

Think I'll go with your first solution, ktekinay

Happy New Year :D


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group