Solved

Substring in ASP

Posted on 2008-06-23
5
5,490 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 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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