测试文件内容如下(可以正常使用):
<%
'*******************************************
'文本转换为Html
'*******************************************
Function Text2Html(Str1)
If isNULL(Str1) Then
Text2Html= " "
Exit Function
End If
Str1=Replace(Str1, "& ", "& ")
Str1=Replace(Str1, " < ", "< ")
Str1=Replace(Str1, "> ", "> ")
Str1=Replace(Str1,VBcrlf, " <br/> ")
Str1=Replace(Str1,chr(34), "" ")
Str1=Replace(Str1,chr(9), " ")
Str1=Replace(Str1, " ", " ")
Text2Html=Str1
End Function
'*****************************************************************************
'获取闭合的全部内容 '(目前只适合于以 <xxx> </xxx> 样式前后呼应的标记,比如 <table> </table> 、 <div> </div> 等)
'*****************************************************************************
Function CutSubContent(theContent1,theContent,startMark,theLen,theCount)
if trim(startMark) = " " then exit function
'获取开头标记和结束标记
MarkLen = Len(startMark)
startMark2 = Lcase(startMark)
startMark = " < " & startMark2 ' <td
endMark = " </ "& startMark2 ' </td
if Instr(theContent1,startMark) <= 0 then exit function
'先把标记之前的内容去掉
theContent1 = Mid(theContent1,Instr(theContent1,startMark))
'重新获得startMark2的值(为什么要重新获得呢?我不知道,反正不重新获得会出错。)
startMark2 = Right(startMark,len(startMark)-1)
If theLen = 0 Then
theLen = Abs(MarkLen + 2)
theContent = Mid(theContent1,theLen)
End If
if InStr(theContent,startMark) < InStr(theContent,endMark) Then '----------------------------------
if InStr(theContent,startMark) > 0 then
theLen = theLen + Abs(InStr(theContent,startMark)+MarkLen+1)
theContent = Mid(theContent1,theLen)
theCount = theCount + 1
else
theLen = theLen + Abs(InStr(theContent,endMark)+MarkLen+1)
theContent = Mid(theContent1,theLen)
theCount = theCount - 1
end if
If Abs(theCount) = 0 Then
response.write Text2Html(Mid(theContent1,1,Abs(theLen)))
response.End
Else
Call CutSubContent(theContent1,theContent,startMark2,theLen,theCount)
End if
Elseif InStr(theContent,startMark) > InStr(theContent,endMark) Then '------------------------------
theLen = theLen + Abs(InStr(theContent,endMark)+MarkLen+2)
theContent = Mid(theContent1,theLen)
theCount = theCount - 1
If Abs(theCount) = 0 Then
response.write Text2Html(Mid(theContent1,1,Abs(theLen-1)))
response.End
Else
Call CutSubContent(theContent1,theContent,startMark2,theLen,theCount)
End if
Else '-----------------------------------------------------