最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp截取中英文字符 程序
时间:2022-07-02 23:15:09 编辑:袖梨 来源:一聚教程网
其实这种方法来限制字数的话还有缺陷的,就是在截取中,英文混合的话,英文也按一个字截取了
下面是经过改良以后的函数,供楼主参考
调用方法不变
function Setlen(str,howlong)
if str="" then
leftstr=""
exit function
end if
dim l,t,c, i
str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
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>=howlong then
leftstr=left(str,i) & "..."
exit for
else
leftstr=str
end if
next
leftstr=replace(replace(replace(replace(leftstr," "," "),chr(34),"""),">",">"),"<","<")
end function
下面是经过改良以后的函数,供楼主参考
调用方法不变
function Setlen(str,howlong)
if str="" then
leftstr=""
exit function
end if
dim l,t,c, i
str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
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>=howlong then
leftstr=left(str,i) & "..."
exit for
else
leftstr=str
end if
next
leftstr=replace(replace(replace(replace(leftstr," "," "),chr(34),"""),">",">"),"<","<")
end function
Public Function CutStr(str, number)
Dim length, llen, i, value
Dim tmp
tmp = str
If isNull(tmp) Then tmp = ""
length = Len(tmp)
llen = 0
For i = 1 To length
value = AscW(Mid(tmp, i, 1))
If value >= -127 AND value <= 127 Then
llen = llen + 1
Else
llen = llen + 2
End If
'debugPrint(Mid(tmp, i, 1) & ":" & value & "--" & llen)
If llen >= number-3 Then
CutStr = Left(tmp, i) & "..."
Exit Function
End If
Next
CutStr = tmp
End Function
Dim length, llen, i, value
Dim tmp
tmp = str
If isNull(tmp) Then tmp = ""
length = Len(tmp)
llen = 0
For i = 1 To length
value = AscW(Mid(tmp, i, 1))
If value >= -127 AND value <= 127 Then
llen = llen + 1
Else
llen = llen + 2
End If
'debugPrint(Mid(tmp, i, 1) & ":" & value & "--" & llen)
If llen >= number-3 Then
CutStr = Left(tmp, i) & "..."
Exit Function
End If
Next
CutStr = tmp
End Function
相关文章
- poipiku网站如何打开-poipiku官网网页版访问入口 01-06
- uc网盘网页版官方入口-UC网盘网页版快捷登录 01-06
- 全免费影视软件哪个最好用-全免费电视电影软件推荐 01-06
- 悟空浏览器怎样直接打开网页-悟空浏览器一键直达网页技巧分享 01-06
- 谷歌google官方入口-Google官方网站入口 01-06
- 漫画天堂最新版本下载入口-漫画天堂官方正版下载入口汇总 01-06