Solved

Substring in ASP

Posted on 2008-06-23
5
5,486 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now