asp如何调用文章内容的前50个汉字,去除图片、空格、html标签等。
2个回答
展开全部
用到以下两个FUNCTION
1、去除HTML代码
Function ClearHtml(Str)
Set re = new RegExp
re.IgnoreCase = True
re.Global = True
re.Pattern = "<(.[^>]*)>"
Str = re.Replace(Str,"")
set re = Nothing
Str=Replace(Str,chr(10),"")
Str=Replace(Str,chr(13),"")
Str=Replace(Str," ","")
'Str=Replace(Str," ","")
Str=Replace(Str," ","")
ClearHtml = Str
End Function
2、截取字数(汉字算2个)
Function CutStr(str,strlen)
If str = "" then
CutStr = ""
Exit Function
End If
str = Replace(str,"<","<")
str = Replace(str,">",">")
str = Replace(str," "," ")
str = Replace(str,""",Chr(34))
str = Replace(str,"'",Chr(39))
str = Replace(str,"—","—")
str = Replace(str,"“","“")
str = Replace(str,"”","”")
l = Len(str)
t = 0
For i = 1 To l
c = Abs(Asc(Mid(str,i,1)))
If c>255 then
t = t+2
Else
t = t+1
End If
If t >= strlen then
CutStr = Left(str,i) & "..."
Exit For
Else
CutStr = str
End If
Next
End Function
====================================
例:<% = CutStr(ClearHtml(NewsContent),100)%>
1、去除HTML代码
Function ClearHtml(Str)
Set re = new RegExp
re.IgnoreCase = True
re.Global = True
re.Pattern = "<(.[^>]*)>"
Str = re.Replace(Str,"")
set re = Nothing
Str=Replace(Str,chr(10),"")
Str=Replace(Str,chr(13),"")
Str=Replace(Str," ","")
'Str=Replace(Str," ","")
Str=Replace(Str," ","")
ClearHtml = Str
End Function
2、截取字数(汉字算2个)
Function CutStr(str,strlen)
If str = "" then
CutStr = ""
Exit Function
End If
str = Replace(str,"<","<")
str = Replace(str,">",">")
str = Replace(str," "," ")
str = Replace(str,""",Chr(34))
str = Replace(str,"'",Chr(39))
str = Replace(str,"—","—")
str = Replace(str,"“","“")
str = Replace(str,"”","”")
l = Len(str)
t = 0
For i = 1 To l
c = Abs(Asc(Mid(str,i,1)))
If c>255 then
t = t+2
Else
t = t+1
End If
If t >= strlen then
CutStr = Left(str,i) & "..."
Exit For
Else
CutStr = str
End If
Next
End Function
====================================
例:<% = CutStr(ClearHtml(NewsContent),100)%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询