Return to Snippet

Revision: 11272
at January 11, 2010 14:41 by jlvallelonga


Updated Code
'This function returns a formatted version of the given web address
function formatWebAddress(byval webAddress)
	webAddress = Replace(webAddress, " ", "")'remove all spaces
	if webAddress <> "" then
		newWebAddress = "*" & webAddress
		if inStr(newWebAddress, "http://") = 0 then 'if http:// is not in the web address
			firstDotPos = inStr(newWebAddress, ".")
			if firstDotPos <> 0 then 'there is at least one dot
				secondDotPos = inStr(firstDotPos + 1, newWebAddress, ".")
				if secondDotPos <> 0 then 'there are at least two dots
					thirdDotPos = 0
					thirdDotPos = inStr(secondDotPos + 1, newWebAddress, ".")
					if thirdDotPos <> 0 then 'if there are more than two dots then it is treated as invalid
						webaddress = ""
					else 'only two dots meaning it's something like www.example.com
						webAddress = "http://" & webAddress & "/"
					end if
				else 'only one dot meaning it's something like example.com
					webAddress = "http://www." & webAddress & "/"
				end if
			else 'if there are no dots then it's not an address
				webAddress = ""
			end if
		else
			if inStrRev(newWebAddress, "/") <> len(newWebAddress) then
				webAddress = webAddress & "/"
			end if
		end if
	end if
	formatWebAddress = webAddress
end function

Revision: 11271
at January 11, 2010 14:19 by jlvallelonga


Updated Code
'This function returns a formatted version of the given web address
function formatWebAddress(byval webAddress)
	webAddress = Replace(webAddress, " ", "")'remove all spaces
	if webAddress <> "" then
		newWebAddress = "*" & webAddress
		if inStr(newWebAddress, "http://") = 0 then 'if http:// is not in the web address
			firstDotPos = inStr(newWebAddress, ".")
			if firstDotPos <> 0 then 'there is at least one dot
				secondDotPos = inStr(firstDotPos + 1, newWebAddress, ".")
				if secondDotPos <> 0 then 'there are at least two dots
					thirdDotPos = 0
					thirdDotPos = inStr(secondDotPos + 1, newWebAddress, ".")
					if thirdDotPos <> 0 then 'if there are more than two dots then it is treated as invalid
						webaddress = ""
					else 'only two dots meaning it's something like www.example.com
						webAddress = "http://" & webAddress & "/"
					end if
				else 'only one dot meaning it's something like example.com
					webAddress = "http://www." & webAddress & "/"
				end if
			else 'if there are no dots then it's not an address
				webAddress = ""
			end if
		else
			if inStrRev(newWebAddress, "/") <> len(newWebAddress) then
				webAddress = webAddress & "/"
			end if
		end if
	end if
	response.write "webAddress is : " & webAddress & "<br />"
	formatWebAddress = webAddress
end function

Revision: 11270
at January 11, 2010 12:53 by jlvallelonga


Updated Code
function formatWebAddress(webAddress)
	if webAddress <> "" then
		newWebAddress = "*" & webAddress
		if inStr(newWebAddress, "http://") = 0 then
			firstDotPos = inStr(newWebAddress, ".")
			if firstDotPos <> 0 then
				secondDotPos = inStr(firstDotPos + 1, newWebAddress, ".")
				if webAddress <> "" then
					if secondDotPos = 0 then
						webAddress = "http://www." & webAddress
					else
						webAddress = "http://" & webAddress
					end if
				end if
			end if
			webAddress = webAddress & "/"
		else
			if inStrRev(newWebAddress, "/") <> len(newWebAddress) then
				webAddress = webAddress & "/"
			end if
		end if
	end if
	formatWebAddress = webAddress
end function

Revision: 11269
at January 29, 2009 15:06 by jlvallelonga


Initial Code
function formatWebAddress(webAddress)
	newWebAddress = "*" & webAddress
	if inStr(newWebAddress, "http://") = 0 then
		firstDotPos = inStr(newWebAddress, ".")
		if firstDotPos <> 0 then
			secondDotPos = inStr(firstDotPos + 1, newWebAddress, ".")
			if webAddress <> "" then
				if secondDotPos = 0 then
					webAddress = "http://www." & webAddress
				else
					webAddress = "http://" & webAddress
				end if
			end if
		end if
	end if
	formatWebAddress = webAddress
end function

Initial URL


Initial Description
this function formats a web address for use in a link

Initial Title
Format Web Address

Initial Tags
format

Initial Language
ASP