weee
01-03-2005, 04:47 PM
How can I get the last folder name of a URL?
Thanks!
Thanks!
|
Click to See Complete Forum and Search --> : Getting the last folder name of a URL weee 01-03-2005, 04:47 PM How can I get the last folder name of a URL? Thanks! russell 01-03-2005, 05:55 PM Dim str Dim fld Dim pStart Dim pEnd str = "http://www.webdeveloper.com/forum/showthread.php?s=&threadid=52778" pEnd = InStrRev(str, "/") pStart = InStrRev(str, "/", Len(str) - pEnd) + 1 Response.Write Mid(str, pStart, pEnd - pStart) will write out "forum" make sure you trap for errors. weee 01-04-2005, 07:52 PM What errors to trap? russell 01-04-2005, 11:50 PM well, suppose we change this: str = "http://www.webdeveloper.com/forum/showthread.php?s=&threadid=52778" To str = "http://www.webdeveloper.com" What happens? An "Invalid Procedure Call" that's what. weee 01-06-2005, 11:42 AM Thanks a lot Russel but I think it's impossible to fix all the traps. The domain can be a tricky one like search.yahoo.co.uk or something like that... You think it can be fixed at all? russell 01-06-2005, 12:37 PM sure it can. what exactly are you trying to do? play around with the code i posted, writing out the values of the variables, and try different combinations of addresses. the easiest error handler would be something like this Dim strToWrite On Error Resume Next '' ignore error for now strToWrite = Mid(str, pStart, pEnd - pStart) If err.Number = 0 Then '' there was no error Response.Write strToWrite End If On Error Goto 0 '' stop ignoring errors you could also check to pEnd - pStart is less that pStart (an error condition when calling the Mid function). Additionally, you can check for other substrings if a "/" doesn't exist in the url. lots of things u can do. weee 01-06-2005, 07:43 PM It's really complicated. I'll try... Thanks for your help! webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |