当前位置: 代码迷 >> ASP >> 自己写了一个函数,测试可以,但在程序里就报MID的错。解决办法
  详细解决方案

自己写了一个函数,测试可以,但在程序里就报MID的错。解决办法

热度:178   发布时间:2012-02-25 10:01:48.0
自己写了一个函数,测试可以,但在程序里就报MID的错。
测试文件内容如下(可以正常使用):

<%
'*******************************************
'文本转换为Html
'*******************************************
Function   Text2Html(Str1)
If   isNULL(Str1)   Then
Text2Html= " "
Exit   Function
End   If
Str1=Replace(Str1, "& ", "&amp; ")
Str1=Replace(Str1, " < ", "&lt; ")
Str1=Replace(Str1, "> ", "&gt; ")
Str1=Replace(Str1,VBcrlf, " <br/> ")
Str1=Replace(Str1,chr(34), "&quot; ")
Str1=Replace(Str1,chr(9), "&nbsp;&nbsp;&nbsp; ")
Str1=Replace(Str1, "   ", "&nbsp; ")  
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   '-----------------------------------------------------
  相关解决方案