asp如何调用文章内容的前50个汉字,去除图片、空格、html标签等。

 我来答
仅此衣款Cq4ec
2011-12-23 · TA获得超过291个赞
知道小有建树答主
回答量:280
采纳率:0%
帮助的人:285万
展开全部
用到以下两个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)%>
东方行
2011-12-23 · 超过85用户采纳过TA的回答
知道小有建树答主
回答量:270
采纳率:0%
帮助的人:195万
展开全部
先用正则 去除所有html代码
.Pattern = "<[^>]*>"

再取前50个字了
追问
能粘个完整的代码看看吗?
谢谢
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式