New topic: SOLVED: How to get the file name from an URL?
<http://forums.realsoftware.com/viewtopic.php?t=46371> Page 1 of 1 [ 4 posts ] Previous topic | Next topic Author Message ojan Post subject: SOLVED: How to get the file name from an URL?Posted: Fri Dec 28, 2012 8:32 am Joined: Fri Oct 16, 2009 12:05 pm Posts: 21 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 markwalsh Post subject: Re: How to get the file name from an URL?Posted: Fri Dec 28, 2012 10:43 am Joined: Wed May 20, 2009 4:43 pm Posts: 914 Look at the Split command. _________________ RB 2009r4 Windows XP Top ktekinay Post subject: Re: How to get the file name from an URL?Posted: Fri Dec 28, 2012 11:25 am Joined: Mon Feb 05, 2007 5:21 pm Posts: 322 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 ojan Post subject: Re: How to get the file name from an URL?Posted: Fri Dec 28, 2012 2:31 pm Joined: Fri Oct 16, 2009 12:05 pm Posts: 21 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 Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 4 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
