ASP怎么截取字符串。就截取前40个汉字

ASP怎么截取字符串。就截取前40个汉字???
2025-02-25 04:37:37
推荐回答(2个)
回答1:

<% 'txt是字符内容,length是要截取多少个字符 Function GetStringLength(txt,length) dim i i=1 y=0 txt=trim(txt) for i=1 to len(txt) j=mid(txt,i,1) if asc(j)>=0 and asc(j)<=127 then '汉字外的其他符号,如:!@#,数字,大小写英文字母 y=y+0.5 else '汉字 y=y+1 end if if -int(-y) >= length then '截取长度 txt = left(txt,i) exit for end if next response.write txt End Function %> 调用方法: <%call GetStringLength(txt,length)%>

回答2:

最简单的: <% if len(rs("title")) > 40 then '判断字符串的长度 response.Write left(rs("title"),40)&" ..." else response.write rs("title") end if %>