README.md

December 4, 2022 ยท View on GitHub

Return Only Page Name

Description

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.

More Info

Submitted On
Bysnowboardr
LevelBeginner
User Rating5.0 (10 globes from 2 users)
CompatibilityASP (Active Server Pages)
CategoryCoding Standards
WorldASP / VbScript
Archive File

Source 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
%>