Posted By

jlvallelonga on 01/29/09


Tagged

format formatting Website address


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

nelda751
benrudolph
Barlon
asifrizvigmailcom


Format Web Address


 / Published in: ASP
 

this function formats a web address for use in a link

  1. 'This function returns a formatted version of the given web address
  2. function formatWebAddress(byval webAddress)
  3. webAddress = Replace(webAddress, " ", "")'remove all spaces
  4. if webAddress <> "" then
  5. newWebAddress = "*" & webAddress
  6. if inStr(newWebAddress, "http://") = 0 then 'if http:// is not in the web address
  7. firstDotPos = inStr(newWebAddress, ".")
  8. if firstDotPos <> 0 then 'there is at least one dot
  9. secondDotPos = inStr(firstDotPos + 1, newWebAddress, ".")
  10. if secondDotPos <> 0 then 'there are at least two dots
  11. thirdDotPos = 0
  12. thirdDotPos = inStr(secondDotPos + 1, newWebAddress, ".")
  13. if thirdDotPos <> 0 then 'if there are more than two dots then it is treated as invalid
  14. webaddress = ""
  15. else 'only two dots meaning it's something like www.example.com
  16. webAddress = "http://" & webAddress & "/"
  17. end if
  18. else 'only one dot meaning it's something like example.com
  19. webAddress = "http://www." & webAddress & "/"
  20. end if
  21. else 'if there are no dots then it's not an address
  22. webAddress = ""
  23. end if
  24. else
  25. if inStrRev(newWebAddress, "/") <> len(newWebAddress) then
  26. webAddress = webAddress & "/"
  27. end if
  28. end if
  29. end if
  30. formatWebAddress = webAddress
  31. end function

Report this snippet  

You need to login to post a comment.