发布网友 发布时间:2024-10-24 05:01
共1个回答
热心网友 时间:2024-10-24 16:40
给你个函数
'**************************
'函数名: Cut_String
'参 数: s_strsrc: 字符串
'参 数: length: 限定长度
'参 数: points: true为有"...",false为无
'返 回: String
'作 用: 截断字符串
'**************************
function cut_string(byval s_strsrc, byval i_length, byval b_points)
dim x, y, i, txt
if trim(s_strsrc) = "" or isnull(s_strsrc) then
cut_string = ""
exit function
end if
txt = Replace(Replace(Replace(Replace(s_strsrc," "," "),""",Chr(34)),">",">"),"<","<")
x = len(txt)
y = 0
if x >= 1 then
for i = 1 to x
if asc(mid(txt, i, 1)) < 0 or asc(mid(txt, i, 1)) > 255 then '如果是汉字
y = y + 2
else
y = y + 1
end if
if y >= i_length then
if b_points then
txt = left(txt, i) & "..."
else
txt = left(txt, i)
end if
exit for
end If
next
cut_string = txt
else
cut_string = ""
end If
end function