Link to home
Start Free TrialLog in
Avatar of tia_kamakshi
tia_kamakshiFlag for United Arab Emirates

asked on

Substring in ASP

Hi,

I am working on ASP project

I have a string below

I wanted to remove all the text  after the last string  "\" and "\" this also get deleted.

For Example if string has text

1. \projects\AspImageProject\ImageUpload\Processed\ASPImageProject\ImageFilePath

then after substring I should get the result string as

\projects\AspImageProject\ImageUpload\Processed\ASPImageProject

2.

If String is
\projects\AspImageProject\ImageUpload\Processed\ASPImageProject

then result substring should be

\projects\AspImageProject\ImageUpload\Processed


Can anyone help me writting this in ASP

Many Thanks
Avatar of Member_2_3718378
Member_2_3718378

Try this out:
Function GetAbsolutePageName(ByVal sURL)
	Dim sPageName
	
	sPageName = sURL
	If IsValidString(sURL) Then
		If InStrRev(sURL, "\") Then
			sPageName = Right(sURL, Len(sURL)-InStrRev(sURL, "\"))
		End If
	End If
	
	GetAbsolutePageName = sPageName
End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Member_2_3718378
Member_2_3718378

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tia_kamakshi

ASKER


Hi,

Thanks for your help.

I am getting hard to use it. I havn't work much on ASP. But I workes on ASP.net allot

I am using your code as below. And it is giving me blank value. Can you please help me in using this function
 

<a href='browseDir.asp?folderdPath=<%= GetAbsolutePath(request.querystring("folderdPath")) %>'>UP</a></b>

<%

Function GetAbsolutePath(ByVal sURL)
         Dim sPagePath

         sPagePath = ""
         If (Trim(sURL & "") <> "") Then
               If InStrRev(sURL, "\") Then
                     sPagePath = Left(sURL, InStrRev(sURL, "\")-1)
               End If
         End If

         GetAbsolutePath = sPagePath
End Function

%>

Many Thanks
Many Thanks
You may want to add some checks but it boils down to this

s = "\projects\AspImageProject\ImageUpload\Processed\ASPImageProject\ImageFilePath"
s = Left(s, InstrRev(s,"\")-1)
Response.Write s

Or using your function. Assuming it's ASP (Classic) forget about the byVal:

Response.Write GetAbsolutePath("\projects\AspImageProject\ImageUpload\Processed\ASPImageProject\ImageFilePath")

Function GetAbsolutePath(sURL)
         Dim sPagePath
         sPagePath = ""
         If (Trim(sURL & "") <> "") Then
               If InStrRev(sURL, "\") > 0  Then
                     sPagePath = Left(sURL, InStrRev(sURL, "\")-1)
               End If
         End If
         GetAbsolutePath = sPagePath
End Function