Solved

Substring in ASP

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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