13Oct2006
Filed under: Website
Author: Ahlang
vbs中自带的len及left函数无法对中文字符长度进行正确的截取,可使用下2函数替代。
- <%
- Function Strleft(Str,L)
- Temp_Str=Len(Str)
- For I=1 To Temp_Str
- Test_Str=(Mid(Str,I,1))
- Strleft=Strleft&Test_Str
- If Asc(Test_Str)>0 Then
- lens=lens+1
- Else
- lens=lens+2
- End If
- If lens>=L Then Exit For
- Next
- End Function
-
- function strLength(str)
- ON ERROR RESUME NEXT
- dim WINNT_CHINESE
- WINNT_CHINESE = (len("中国")=2)
- if WINNT_CHINESE then
- dim l,t,c
- dim i
- l=len(str)
- t=l
- for i=1 to l
- c=asc(mid(str,i,1))
- if c<0 then c=c+65536
- if c>255 then
- t=t+1
- end if
- next
- strLength=t
- else
- strLength=len(str)
- end if
- if err.number<>0 then err.clear
- end function
- %>
Leave a reply