Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Substring in ASP

Posted on 2008-06-23
5
Medium Priority
?
5,516 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:tia_kamakshi
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:deathtospam
ID: 21848335
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

0
 
LVL 9

Accepted Solution

by:
deathtospam earned 2000 total points
ID: 21848372
Woops -- you wanted the path, not the page name.  Try this function instead:
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

Open in new window

0
 

Author Comment

by:tia_kamakshi
ID: 21853943

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
0
 

Author Closing Comment

by:tia_kamakshi
ID: 31469852
Many Thanks
0
 
LVL 1

Expert Comment

by:kalfs_net
ID: 22367060
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
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

916 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