Search Tools Links Login

Return Only Page Name


It just gets the page name of your page without any slashes or .asp commented for beginners, 4 lines of code. This is a short little snippet I used today on a project, and didn't see anything like it on PSC, so just thought I would share it.
Comments welcome.

Original Author: snowboardr

Code

<%
ScriptName = "/asdfaf/asdf/sfsdf/fas/The_Page_Name.asp"

Function GetPageName(sScriptName)
'# Location of last slash In ScriptName + 1 because we don't want the slash

LastSlashLocation = InstrRev(sScriptName,"/") + 1

'# Location of last period in ScriptName

LastDotLocation = InstrRev(sScriptName,".")

'# Here we find out how long the page name is

ScriptPageNameLength = LastDotLocation - LastSlashLocation

'# Start 1 after the forward slash, and end before the period.
'# Set it to the function by using the function name

GetPageName = Mid(sScriptName,LastSlashLocation,ScriptPageNameLength)
End Function

'# Call Function
Response.Write(GetPageName(ScriptName))
'# Outputs: The_Page_Name
%>

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 70 times

Categories

ASP/ HTML

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.