asp 截取字符串并去除空格 (内容是从Word里面复制的)
<%iflen(rs("P_Content"))>30thenresponse.write(replace(left(rs("P_Content"),60)&"...",...
<%
if len(rs("P_Content"))>30 then
response.write(replace(left(rs("P_Content"),60)&"...","",""))
else
response.write(rs("P_Content"))
end if
%>我这么写的好像效果不太理想。我从网上搜索了
gotTopic(ByVal str, ByVal strlen) 这么调用的<%=gotTopic(rs("P_Content"),20)%>但是<p>之类的全部显示出来了。
Function gotTopic(ByVal str, ByVal strlen)
If str = "" Then
gotTopic = ""
Exit Function
End If
Dim l, t, c, i, strTemp
str = Replace(Replace(Replace(Replace(str, " ", " "), """, Chr(34)), ">", ">"), "<", "<")
l = Len(str)
t = 0
strTemp = str
strlen = CLng(strlen)
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
strTemp = Left(str, i)
Exit For
End If
Next
If strTemp <> str Then
strTemp = strTemp & "…"
End If
gotTopic = Replace(Replace(Replace(Replace(strTemp, " ", " "), Chr(34), """), ">", ">"), "<", "<")
End Function 展开
if len(rs("P_Content"))>30 then
response.write(replace(left(rs("P_Content"),60)&"...","",""))
else
response.write(rs("P_Content"))
end if
%>我这么写的好像效果不太理想。我从网上搜索了
gotTopic(ByVal str, ByVal strlen) 这么调用的<%=gotTopic(rs("P_Content"),20)%>但是<p>之类的全部显示出来了。
Function gotTopic(ByVal str, ByVal strlen)
If str = "" Then
gotTopic = ""
Exit Function
End If
Dim l, t, c, i, strTemp
str = Replace(Replace(Replace(Replace(str, " ", " "), """, Chr(34)), ">", ">"), "<", "<")
l = Len(str)
t = 0
strTemp = str
strlen = CLng(strlen)
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
strTemp = Left(str, i)
Exit For
End If
Next
If strTemp <> str Then
strTemp = strTemp & "…"
End If
gotTopic = Replace(Replace(Replace(Replace(strTemp, " ", " "), Chr(34), """), ">", ">"), "<", "<")
End Function 展开
2个回答
展开全部
Function RemoveHTML(strText)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "<[^>]*>"
RegEx.Global = True
RemoveHTML = RegEx.Replace(strText, "")
End Function
变量=RemoveHTML(rs_job("字段"))
调用这个函数 是去掉 文本编辑器的 <html>
变量= left(replace(变量," ",""),120)
去掉空格,然后120 是 显示的字节
如果不想要 replace(变量," ","") 这样就行了
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "<[^>]*>"
RegEx.Global = True
RemoveHTML = RegEx.Replace(strText, "")
End Function
变量=RemoveHTML(rs_job("字段"))
调用这个函数 是去掉 文本编辑器的 <html>
变量= left(replace(变量," ",""),120)
去掉空格,然后120 是 显示的字节
如果不想要 replace(变量," ","") 这样就行了
展开全部
Function gotTopic(ByVal str, ByVal strlen)
Do While (InStr(str, Space(1)))
str = Replace(str, Space(1), "")
Loop
If Len(str) > strlen Then
gotTopic = Left(str, strlen) & "..."
Else
gotTopic = str
End If
End Function
网页中显示了<p>标记,是复制过去的内容么?如果是建议利用正则表达式,或定位"<"和">"后用mid()获取标记替换掉
Do While (InStr(str, Space(1)))
str = Replace(str, Space(1), "")
Loop
If Len(str) > strlen Then
gotTopic = Left(str, strlen) & "..."
Else
gotTopic = str
End If
End Function
网页中显示了<p>标记,是复制过去的内容么?如果是建议利用正则表达式,或定位"<"和">"后用mid()获取标记替换掉
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询