Solved

Substring in ASP

Posted on 2008-06-23
5
5,499 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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/…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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