ASP static file Tool

Source: Internet
Author: User

<%
'''''''''''''''''''''''''''''''''''''''' ''''''''''''
'Set template = new templatestate
'Template.opentemplate('template.html ') read the template content
'Template. value = "value" content
'Template. replacekeyword keyword URL replacement keyword
'Template. replacetext ("/$ content/$") replaces the template content
'Template. savetemplateas ("1.html") to generate a file
'''''''''''''''''''''''''''''''''''''''' ''''''''''''
Class templatestate
Public filepath
Public startposition
Public endposition
Public Value
Public templatecontent

Public FSO
Public File
Public RegEx

Private sub class_initialize
Filepath = ""
Startposition = ""
Endposition = ""
Value = ""
Templatecontent = ""
Set FSO = server. Createobject ("scripting. FileSystemObject ")
Set RegEx = new Regexp
With RegEx
. Multiline = true
. Ignorecase = true
. Global = true
End
End sub

Private sub class_terminate
Filepath = ""
Startposition = ""
Endposition = ""
Value = ""
Set RegEx = nothing
Set file = nothing
Set FSO = nothing
End sub

Private function filterstr (STR)
Filterstr = Str
If STR = "" Or isnull (filterstr) then
Filterstr = ""
Else
Filterstr = Replace (filterstr ,"/","//")
Filterstr = Replace (filterstr ,"(","/(")
Filterstr = Replace (filterstr ,")","/)")
Filterstr = Replace (filterstr ,"*","/*")
Filterstr = Replace (filterstr ,"? ","/? ")
Filterstr = Replace (filterstr ,"{","/{")
Filterstr = Replace (filterstr ,"}","/}")
Filterstr = Replace (filterstr ,".","/.")
Filterstr = Replace (filterstr, "+", "/+ ")
Filterstr = Replace (filterstr ,"[","/[")
Filterstr = Replace (filterstr, "]", "/]")
End if
End Function

Public Function opentemplate (sfilepath)
Set file = FSO. opentextfile (server. mappath (sfilepath), 1)
Templatecontent = file. readall ()
File. Close
Filepath = sfilepath
End Function

Public Function replacetemplate ()
If startposition = "" Or endposition = "" Or templatecontent = "" then
Exit Function
End if
Dim strpattern
Strpattern = filterstr (startposition) & "[/S] *? "& Filterstr (endposition)
RegEx. pattern = strpattern
Templatecontent = RegEx. Replace (templatecontent, startposition & vbcrlf & Value & vbcrlf & endposition)
End Function

Public Function replacetext (patrn)
RegEx. pattern = patrn
Templatecontent = RegEx. Replace (templatecontent, value)
End Function

Public Function replacekeyword (keyword, URL)
RegEx. pattern = keyword
Value = RegEx. Replace (value, "<a href =" & URL & ">" & keyword & "</a> ")
End Function

Public Function savetemplate ()
Set file = FSO. opentextfile (server. mappath (filepath), 2)
File. Write templatecontent
File. Close
End Function

Public Function savetemplateas (sfilepath)
Set file = FSO. opentextfile (server. mappath (sfilepath), 2, true)
File. Write templatecontent
File. Close
End Function
End Class
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.